Rat chases its cheese

only one test case is getting accepted though my code is correct

you need to make visited array so that you dont go through same path twice, and you have mixed up m and n in your code.
Corrected Code