Cyclisation reaction through hydrazine

The following reaction confuses me - I don't understand how and why it happened (couldn't figure out the mechanism):

I thought this is some Wolff Kishner sort of reduction, but the reagents don't match (no alkaline medium). I am not sure how hydrazine lead to cyclisation - for starters, I guess it added to the carbonyl oxygen (aldehyde, as it is more reactive) as an ammonia derivative to form a hydrazone. What's next?

• What's next in a further nucleophilic attack by the NH2 at the other end of the hydrazone on the ketone – Waylander Jul 4 '18 at 15:52
• I did that, what happens then? – arya_stark Jul 4 '18 at 16:04
• Elimination of water to form the product drawn – Waylander Jul 4 '18 at 16:22
• Could you please add the mechanism as an answer? I'm not able to figure out how dehydration would occur after internal nucleophilic attack by the nitrogen on carbonyl oxygen. Thanks. – arya_stark Jul 4 '18 at 17:23

It's essentially just the same reaction once and then over again. The basic medium of the Wolf-Kishner reduction is to remove the hydrazone hydrogen, releasing the $\ce{C=N}$ electrons onto the carbon. In this reaction, the hydrazone instead further reacts with the other carbonyl to form an aromatic 6-membered ring.