
ZOJ Problem Set  2594
The city where Peter lives has the form of the rectangle with M streets running from east to west and N streets running from north to south. Recently, because of preparations for the celebration of the city's 3141^{st} birthday, some street sectors has been closed for driving. Peter lives in the house next to point (1, 1) and works next to the point (N, M). He always drives from home to work by his car using the shortest possible path. Of course, he can't drive through closed sectors. Since there can be many shortest pathes between his house and his work, he may choose any. But Peter doesn't like to turn (he is an inexperienced driver), so he wants to choose the path using the following algorithm: starting from the point (1, 1) he drives either northwards, or eastwards (wherever there is the shortest path available, if there are both, he may choose any). Whenever he comes to the junction he must decide where to go. If there is only one direction he can drive to stay on the shortest path, he must choose that direction. In the other case he would like to choose the direction giving priority to driving forward, that is, if he can drive forward and still stay on some shortest path, he would go forward. If he can't drive forward to stay on the shortest path, he would choose any available direction. Help Peter to create the path from his house to his work using the rules described. Input The input contains multiple test cases. The first line of the input is a single integer T (1 <= T <= 24) which is the number of test cases. T test cases follow, each preceded by a single blank line. The first line of each test case contains integer numbers M and N (2 <= M,N <= 400). Next 2M  1 lines contain 2N  1 characters each, representing the city map. House blocks are marked with spaces, junctions with '+', open sectors with '' and '', closed sectors with spaces. Peter's house is at the lowerleft corner of the map, his work is at the upperright corner. Output On the first line of each test case print the direction Peter should choose first, 'N' or 'E'. On the second line output the sequence of latin letters 'F', 'L' and 'R' representing Peter's behaivour on junctions  go forward, turn left or right respectively. If there are several paths Peter can choose from, output any. You must output Peter's action on the junction even if he has no choice due to closed streets. It is guaranteed that there will always be the way for Peter to get from home to work. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case. Sample Input 1 4 4 ++ ++    + +++   ++++   ++++ Sample Output N RFLRL Author: Andrew Stankevich Source: Andrew Stankevich's Contest #5 