public static void main(String[] args) throws IOException {
		long inicio = System.currentTimeMillis();
		StringBuilder out = new StringBuilder();
		BufferedReader in;
		File archivo = new File("entrada");
		if (archivo.exists())
			in = new BufferedReader(new FileReader(archivo));
		else
			in = new BufferedReader(new InputStreamReader(System.in));

		String line = "";
		char cad[];
		int n = Integer.parseInt(in.readLine());
		map = new char[5][5];

		int x = 0;
		int y = 0;
		for (int i = 0; i < n; i++) {
			max = Integer.MAX_VALUE;
			for (int j = 0; j < 5; j++) {
				cad = in.readLine().toCharArray();
				for (int k = 0; k < cad.length; k++) {
					if (cad[k] == '0')
						map[j][k] = '0';
					else
						map[j][k] = '1';
					if (cad[k] == ' ') {
						x = j;
						y = k;
						map[j][k] = ' ';
					}
				}
			}

			dfs(map, x, y, 0, -1, -1);
			if (max != Integer.MAX_VALUE) {
				out.append("Solvable in " + max + " move(s).\n");
			} else {
				out.append("Unsolvable in less than 11 move(s).\n");
			}

		}
		System.out.print(out);
		if (archivo.exists())
			System.out.println("Tiempo transcurrido : "
					+ (System.currentTimeMillis() - inicio) + " milisegundos.");
	}