Can anyone tell me the approach to this problem?

https://www.codechef.com/COOK127C/problems/MATXOR

Can anyone please help me why my code for this problem is wrong:
https://www.codechef.com/submit/MATXOR