// Arup Guha
// 11/5/2015
// Solution to 1999 UCF High School Contest Problem: Inspector Doohickey

import java.util.*;

public class maze {

	// Useful constants.
	final public static int N = 10;
	final public static int[] DX = {-1,0,0,1};
	final public static int[] DY = {0,-1,1,0};
	final public static String[] DIR = {"N","W","E","S"};

	// Easier if everyone can see this.
	public static char[][] grid;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			// Read in the grid.
			grid = new char[N][];
			for (int i=0; i<N; i++)
				grid[i] = stdin.next().toCharArray();

			// Solve and output result.
			System.out.println("Maze #"+loop);
			System.out.println(bfs('L','I'));
			System.out.println(bfs('I','X'));
			System.out.println();
		}
	}

	// Returns shortest valid path from character start to character end in grid.
	// Assumes that start appears exactly once in the grid.
	public static String bfs(char start, char end) {

		// Get the starting and ending locations.
		int sLoc = getLoc(start);

		// Set up for BFS.
		LinkedList<pair> q = new LinkedList<pair>();
		q.offer(new pair(sLoc,""));
		boolean[] used = new boolean[N*N];
		used[sLoc] = true;

		// BFS loop.
		while (q.size() > 0) {

			// Get next item.
			pair cur = q.poll();
			if (grid[cur.loc/N][cur.loc%N] == end) return cur.path;

			// Go through next possible locations.
			for (int i=0; i<DX.length; i++) {
				int x = cur.loc/N + DX[i];
				int y = cur.loc%N + DY[i];

				// Only add to queue if we've never been there and it's a valid square to move to.
				if (inbounds(x,y) && !used[N*x+y] && grid[x][y] != 'W') {
					q.offer(new pair(N*x+y,cur.path+DIR[i]));
					used[N*x+y] = true;
				}
			}
		}

		// Should never get here.
		return "";
	}

	// Returns the first location lexicographically in the grid where c is found.
	public static int getLoc(char c) {

		// Find the first index where c is located. Return the index as one value.
		for (int i=0; i<N; i++)
			for (int j=0; j<N; j++)
				if (grid[i][j] == c)
					return N*i+j;

		// Should never get here for this problem.
		return -1;

	}

	// Returns true iff (x,y) is a valid point in grid.
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < N && y >= 0 && y < N;
	}
}

class pair {

	public int loc;
	public String path;

	public pair(int num, String p) {
		loc = num;
		path = p;
	}
}