Everyone knows the greedy snake game.Now this problem is the same as it.In a room,the rat is seeking food.Food will appear one by one after the rat gets one food.Food will only appear in the blanks.
Input until EOF.
There two positive integers m(2<m<50) and n(2<n<50) means the size of room.
Then input the room.The room just includes T,X,O.T is the starting point of rat,X means the rat can not go,O means the blank.
Next line follows a positive integer t(0<t<100) means the number of food.
Then t lines follows.Each line includes two integers x(x>0) and y(y>0).x is the coordinate of line,y is the coordinate of column.
You should output the minimum step number the rat should do when he gets all of food.