// Arup Guha
// 11/5/2015
// Verifier for 1999 UCF High School Contest Problem: Inspector Doohickey

import java.util.*;
import java.io.*;

public class verifymaze {

	// Useful constants.
	final public static int N = 10;
	final public static String ALLDIR = "NWES";

	// Easier if everyone can see this.
	public static char[][] grid;

	public static void main(String[] args) throws Exception {

		// args[0] = input
		Scanner stdin = new Scanner(new File(args[0]));
		int numCases = stdin.nextInt();

		// args[1] = student solution.
		Scanner student = new Scanner(new File(args[1]));

		// 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();

			// Get student response.
			student.nextLine();
			String part1 = student.nextLine().trim();
			String part2 = student.nextLine().trim();
			student.nextLine();

			// See if first part is invalid.
			if (!verify(part1, getLoc('L'), 'I')) {
				System.out.println("ERROR CASE "+loop+" getting to Inspector.");
				break;
			}

			// Then second part.
			if (!verify(part2, getLoc('I'), 'X')) {
				System.out.println("ERROR CASE "+loop+" getting to Inspector.");
				break;
			}
		}
	}

	// Simulates walking using the directions in dir from start. If the directions lead
	// to an invalid square (or out of bounds) or don't end at end, returns false.
	public static boolean verify(String dir, int start, char ch) {

		int x = start/N;
		int y = start%N;

		for (int i=0; i<dir.length(); i++) {
			char c = dir.charAt(i);
			if (!ALLDIR.contains(""+c))	return false;
			if (c == 'N') x--;
			else if (c == 'W') y--;
			else if (c == 'E') y++;
			else x++;
			if (!inbounds(x,y)) return false;
			if (grid[x][y] == 'W') return false;
		}
		return grid[x][y] == ch;
	}

	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;
	}
}