XYSTR- June Long Challenge

https://www.codechef.com/viewsolution/34628183. Can you please tell why the code is giving a WA? It is passing all the test cases I have tried manually. Please provide the test case where it fails. Thanks