Yesterday, my friend from Robolution asked me to to solve a problem. They were organizing a contest. In that they have an arena made up of small squares placed as a grid. Your bot cannot go to some squares X. The aim of the bot is to reach the sqaure F nearest to the destination at square D. Now he is stuck with the program. Your task is to write a program so that the bot reaches to a square nearest reachable to the destination or the destination if possible.
All squares where you can move are denoted as A
All squares where you can not move are denoted as X.
First line is the number of test cases T.
For each test case you are give the number of rows (R) and columns (C) separeated by space.
Next two lines consist of the cordinates of sourse S and Destination D separated by space.
Next R lines contain the list of square in each C coloumn.
you need to list the cordinates of square F in first line and number of moves in the second.
In case of two squares being at same least distance to the destination, take the one which requires shortest path.
The input will have a particular answer only.
Problem by: Piyush Garg