For some test case code is not working

for test case 0 my code is not working can you pls suggest me improvement in my code

https://ide.codingblocks.com/s/201092 link of my code

Hi @jaynish for the input
5
A
B
C
D
E
5
C A
D A
B D
E B
E C

your output :
E C B D A

expected output:
E B C D A

Yes Mam , what changes i need to do in my code so… it works for all the test case?

@jaynish try to figure out for this given test case why is your code failing? There is no relation given between B and C and B is listed before C, so it should be printed before. Have you taken that into consideration?
Let me know if you are stuck I will help you.

Thank you mam ,Got the hint