This is an aldol condensation reaction.There are few steps take place in this reaction:
Step 1: Acid base reaction takes place in between base and alpha hydrogen of cyclopentadienyl and carbanion is formed.
Step 2: In this step formed carbanion behaves as nucleophile and attack on carbonyl compound carbon.
Step 3: Water gives proton and release hydroxide ion as shown below
Therefore, the compound X is