#include <iostream>
using namespace std;

const bool CHECKFORTIES = false;

struct tile
{
	int n1, n2;
	bool used;
	bool horiz;
	int r, c;
} tiles[21];
int index[7][7];
int grid[5][5];

void initTiles()
{
	int k=0;
	for(int i=1; i<=6; i++)
		for(int j=i; j<=6; j++) {
			tiles[k].n1 = i;
			tiles[k].n2 = j;
			index[i][j] = index[j][i] = k;
			k++;
		}
}

void advance(int& r, int& c)
{
	while (grid[r][c] != 0) {
		if (++c == 5) {
			c = 0;
			r++;
		}
	}
}
	
int main()
{
	int ncases;
	int n1, n2, m1, m2;
	int scount;
	cin >> ncases;
	initTiles();
	for(int icase=1; icase<=ncases; icase++) {
		cout << "Case " << icase << ":" << endl;
		scount = 0;
		for(int i=0; i<21; i++)
			tiles[i].used = false;
		for(int i=0; i<5; i++)
			for(int j=0; j<5; j++)
				grid[i][j] = 0;
		int r=0, c=0;
		for(int i=0; i<13; i++) {
			char ch;
			int n1, n2;
			cin >> ch;
			if (ch == 'H') {
				cin >> n1 >> n2;
				int j = index[n1][n2];
				if (tiles[j].used)
					cout << "ERROR: repeated tile " << tiles[j].n1 << ',' << tiles[j].n2 << endl;
				if (grid[r][c+1] != 0)
					cout << "ERROR: overlap tile " << tiles[j].n1 << ',' << tiles[j].n2 << " at " << r << ',' << c+1 << endl;
				tiles[j].used = true;
				tiles[j].horiz = true;
				tiles[j].r = r, tiles[j].c = c;
				grid[r][c] = n1;
				grid[r][c+1] = n2;
				advance(r,c);
			}
			else if (ch == 'V') {
				cin >> n1 >> n2;
				int j = index[n1][n2];
				if (tiles[j].used)
					cout << "ERROR: repeated tile " << tiles[j].n1 << ',' << tiles[j].n2 << endl;
				if (grid[r+1][c] != 0)
					cout << "ERROR: overlap tile " << tiles[j].n1 << ',' << tiles[j].n2 << " at " << r+1 << ',' << c << endl;
				tiles[j].used = true;
				tiles[j].horiz = false;
				tiles[j].r = r, tiles[j].c = c;
				grid[r][c] = n1;
				grid[r+1][c] = n2;
				advance(r,c);
			}
			else {
				if (scount == 1)
					cout << "ERROR: more than one singleton" << endl;
				cin >> grid[r][c];
				scount++;
				advance(r,c);
			}
		}
	}
}
