Rat chases its cheese problem

https://ide.codingblocks.com/s/63071

The code is showing no output in one test case. how to rectify it ?

Hi Yukti, try to dry-run your code for the following test case:
5 7
OXOOOOX
OXOXOXX
OXOXOOX
OOOXOXX
XXOXXXX