CHEFS IN QUEUE (CHFQUEUE) WRONG ANSWER

I have tried to solve this problem Contest Page | CodeChef using stacks as told in the editorial. CHFQUEUE - Editorial
I am getting WA for all test cases and I am unable to find what’s wrong in the code.