For Taiwanese people, it is well-known that Taipei station is just like a maze.
Paul is a foreign visitor coming to Taipei for the first time.
To figure out the exact position, he sent a message to his friend, Tommy, for help.
Since the description from Paul is quite confusing, Tommy finds an easier way for Paul to provide the information.
There will be a 2D map composed of alphabets(e.g., a, c, or H), which implies the Taipei station.
First, given the position P (e.g., (2, 3)), he must find the smallest(Using ASCII code) char around him (should be at most eight choices).
Note that if there are duplicated chars, please choose the element with larger index:
Next,
if the chosen char is in ['a', 'f', 'k', 'p', 'E', 'J', 'O', 'T'], please move your current position to the left;
if the chosen char is in ['b', 'g', 'l', 'q', 'D', 'I', 'N', 'S'], please move your current position to the right;
if the chosen char is in ['c', 'h', 'm', 'r', 'C', 'H', 'M', 'R'], please move your current position to the up;
if the chosen char is in ['d', 'i', 'n', 's', 'B', 'G', 'L', 'Q'], please move your current position to the down;
if the chosen char is in ['e', 'j', 'o', 't', 'A', 'F', 'K', 'P'], move your current position into the chosen char, and from now on, you have to find the biggest char, vise versa(If the current mode is to find the biggest char, start to find the smallest one);
if the chosen char isn't in the above choices, please move your current position into the chosen char.
There are two terminal situations:
(1) You reach the edge Your next step is outside the map (Current movement Next movement is illegal).
(2) You reach the given steps.
Once the whole process ends, please print the texts you've visited.
There will be 4 parts for the input:
(1) The size of the map, n. (5 <= n <= 100)
(2) The maximum steps in the process, S. (1 <= S <= n**2 )
(3) The initial position(x, y).It is guaranteed that it is on the map.
(4) The text map with size n*n.
All of them are separated by a '\n'.
The texts you've traversed.
Note that you dont' have to print "\n" at the end.