// Arup Guha
// 10/20/12 - 10/24/12
// Solution to Greater NY Regional Problem D: Decoding
import java.util.*;

public class d {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int numCases = stdin.nextInt();

		for (int loop = 1; loop<=numCases; loop++) {

			// Read in code into grid.
			int r = stdin.nextInt();
			int c = stdin.nextInt();
			int[][] grid = new int[r][c];
			String s = stdin.next();
			int place = 0;
			for (int i=0; i<r; i++) {
				for (int j=0; j<c; j++) {
					grid[i][j] = (int)(s.charAt(place) - '0');
					place++;
				}
			}

			// Set up array for answer, and moving around the grid.
			char[] ans = new char[(r*c)/5];
			int dx = 0, dy = 1, x = 0, y = 0;
			for (int i=0; i<(r*c)/5; i++) {

				// Reconstruct the binary value for 5 bits.
				int val = 0;
				for (int j=0; j<5; j++) {

					val = val*2 + grid[x][y];

					// Move like we did in problem C.
					if (x + dx >= r) {
						dy = -1; dx = 0;
					}
					else if (x + dx < 0) {
						dy = 1; dx = 0;
					}
					else if (y + dy >= c) {
						dy = 0; dx = 1;
					}
					else if (y + dy < 0) {
						dy = 0; dx = -1;
					}
					else if (grid[x+dx][y+dy] == -1) {
						if (dx == 1) {
							dx = 0; dy = -1;
						}
						else if (dx == -1) {
							dx = 0; dy = 1;
						}
						else if (dy == 1) {
							dy = 0; dx = 1;
						}
						else {
							dy = 0; dx = -1;
						}
					}
					
					// Mark where we've been before with a -1.
					grid[x][y] = -1;
					x += dx;
					y += dy;
				}

				// Place the answer.
				ans[i] = ' ';
				if (val > 0)
					ans[i] = (char)(val-1+'A');
			} // end s loop

			// Output answer.
			String output = new String(ans);
			System.out.println(loop+" "+output);

		}
	}

}