#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
#define REP(i, n) for(int i=0; i<int(n); i++)
#define pb(x) push_back(x)
struct PII{
	int x, y;
	PII(int x, int y):x(x), y(y){}
	PII(){}
	bool operator<(const PII &a) const {
		if(x!=a.x) return x < a.x;
		else return y < a.y;
	}
};
struct edge{
	int x, y;
	int d; //0 for horizontal
	edge(int x, int y, int d):x(x), y(y), d(d){}
	edge(){}
};
int x[]={0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};
int y[]={0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3};
bool g[4][4][2], f[4][4][2];

int ok(int x, int y, bool g[4][4][2]){
	if(x>=0 && x<4 && y>=0 && y<4
	&& g[x][y][0] && g[x][y][1] && g[x+1][y][0] && g[x][y+1][1])
		return 1;
	else return 0;
}

int cnt(int x, int y, bool d, bool g[4][4][2]){
	int res = 0;
	res += ok(x, y, g);
	if(d){ //vertical
		res += ok(x, y-1, g);
	} else { //horizontal
		res += ok(x-1, y, g);
	}
	return res;
}

const int INF = 0x3f3f3f3f;
int score[2];
vector<edge> E;
int sc[1<<12];
bool vis[1<<12];

int main()
{
	int T;
	scanf("%d", &T);
	REP(tt, T){
	    memset(g, 0, sizeof g);
		E.clear();
		score[0]=score[1]=0;
		int n, a, b, curr=0;
		scanf("%d", &n);
		REP(i, n){
			scanf("%d%d", &a, &b);
			a--, b--;
			PII u(x[a],y[a]);
			PII v(x[b],y[b]);
			if(v<u)swap(u, v);
			int t;
			if(u.x == v.x)t=0;
			else t = 1;
			g[u.x][u.y][t] = true;
			score[curr] += cnt(u.x, u.y, t, g);
			curr ^= 1;
		}
		REP(i, 4){
			REP(j, 4){
				REP(t, 2){
				    if(i==3 && t==1)continue;
				    if(j==3 && t==0)continue;
					if(!g[i][j][t]){
						E.pb(edge(i, j, t));
					}
				}
			}
		}
		//cout<<E.size()<<endl;
		queue<int> q;
		int tttt = 1<<12;
		//REP(i, tttt)sc[i]= -10000;
		memset(sc, 0x9999, sizeof sc);
		memset(vis, 0, sizeof vis);
		//printf("sc[0] = %d\n", sc[0]);
		int mst = 1 << E.size();
		mst --;
		while(!q.empty())q.pop();
		q.push(mst);
		sc[mst] = 0;
		vis[mst] = 1;
		//cout<<"bfs"<<endl;
		while(!q.empty()){
			int st = q.front();
			q.pop();
			memcpy(f, g, sizeof(g));
			REP(i, E.size()){
				if(st&(1<<i)){
					f[E[i].x][E[i].y][E[i].d] = true;
				}
			}
			REP(i, E.size()){
				if(st&(1<<i)){
					int x = E[i].x, y = E[i].y, t = E[i].d, ss = st^(1<<i);
					int pts = cnt(x, y, t, f);
					sc[ss] = max(sc[ss], pts-sc[st]);
					if(!vis[ss]){
					    q.push(ss);
					    vis[ss] = true;
				    }
				}
			}
		}
		//printf("%d %d %d\n", score[0], score[1], sc[0]);
		score[n&1] += sc[0];
		printf("Case #%d: ", tt+1);
		if(score[0]>score[1])puts("Tom200");
		else puts("Jerry404");
	}
}
