WA in Studying Alphabet

https://www.codechef.com/viewsolution/30699995
help me. whats wrong with this code? examples give correct output but wrong answer on submisiion

Try the test case

act
2
dog
cat

ok yeah.doesn’t work.thanks!

it was bool ans=1; being outside the loop wasn’t it?

Yes.