def fun(l):
d = {}
for index in range(len(l)):
d[str(l[index][0])+" "+str(l[index][1])] = index
temp = list(l)
temp.sort()
ans = [''] * len(l)
A, B = 0, 0
for i in range(len(temp)):
low = temp[i][0]
high = temp[i][1]
index = d[str(temp[i][0])+" "+str(temp[i][1])]
if A <= low :
A = high
ans[index] = 'C'
elif B <= low:
B = high
ans[index] = 'J'
else:
return "IMPOSSIBLE"
return "".join(ans)
test = int(input())
ans = []
while test:
i = int(input())
l = []
for i in range(i):
l.append([int(x) for x in input().split()])
ans.append(fun(l))
test -= 1
k = 1
for i in ans:
print("Case #"+str(k)+": "+i)
k += 1