NUKES..Wrong Answer

Can someone please tell me where i am going wrong? Two of my test cases show a wrong answer (test 3 and test 8).Thanks in advance.
Following is the link of my code: ztgorj - Online C++ Compiler & Debugging Tool - Ideone.com

I had written another code but that shows a TLE error for test case 6.
Following is the link to my code : CodeChef: Practical coding for everyone