#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <array>
#include <set>
#include <climits>
#include <sstream>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <numeric>
using namespace std;
using namespace __gnu_pbds;
typedef tree< // find_by_order & order_of_key
int ,
null_type ,
less<int> ,
rb_tree_tag ,
tree_order_statistics_node_update
> new_set;
#define MOD 1000000007
#define MAXN 1002
bool compare(pair<int,int>&i ,pair<int,int>&j){
return (i.second<j.second);
}
int main(void){
#ifdef HELL_JUDGE
freopen("input","r",stdin);
freopen("output","w",stdout);
freopen("error","w",stderr);
#endif
int t; scanf("%d",&t);
for(int tt=1;tt<=t;++tt){
array<int,MAXN>diff_array;
fill(diff_array.begin() , diff_array.end() , 0);
array<pair<int,int>,MAXN>activity;
array<pair<int,int>,MAXN>temp_activity;
map<pair<int,int> , char>answer;
printf("Case #%d: ",tt);
int n;scanf("%d",&n);
for(int i=0;i<n;++i){
int &u = activity[i].first;
int &v = activity[i].second;
scanf("%d%d",&u,&v);
diff_array[u]++;
diff_array[v+1]--;
temp_activity[i] = activity[i];
}
for(int i=1;i<=n;++i){
diff_array[i]+=diff_array[i-1];
}
if(any_of(diff_array.begin() , diff_array.begin()+n,[](int &i){return i>2;})){
puts("IMPOSSIBLE");
continue;
}else{
// let's create two pointer and keep them move , when current work's starting is less then or equal to
// the any of pointer we will fix it to the end of that activity :- that means that activity is done by that person
int c{} , j{};
sort(activity.begin(),activity.begin()+n , compare);
for(int i=0;i<n;++i){
cerr<<activity[i].first<<' '<<activity[i].second<<'\n';
if(c<=activity[i].first){
answer[activity[i]] = 'C';
c = activity[i].second;
}else if(j<=activity[i].first){
answer[activity[i]] = 'J';
j = activity[i].second;
}else{
puts("Something is Wrong");
return 0;
}
}
for(int i=0;i<n;++i){
cout<<answer[temp_activ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TsKfQppbnQgbWFpbih2b2lkKXsKI2lmZGVmIEhFTExfSlVER0UKICAgIGZyZW9wZW4oImlucHV0IiwiciIsc3RkaW4pOwogICAgZnJlb3Blbigib3V0cHV0IiwidyIsc3Rkb3V0KTsKICAgIGZyZW9wZW4oImVycm9yIiwidyIsc3RkZXJyKTsKI2VuZGlmIAogICAgaW50IHQ7IHNjYW5mKCIlZCIsJnQpOwogICAgZm9yKGludCB0dD0xO3R0PD10OysrdHQpewogICAgICAgIGFycmF5PGludCxNQVhOPmRpZmZfYXJyYXk7CiAgICAgICAgZmlsbChkaWZmX2FycmF5LmJlZ2luKCkgLCBkaWZmX2FycmF5LmVuZCgpICwgMCk7CiAgICAgICAgYXJyYXk8cGFpcjxpbnQsaW50PixNQVhOPmFjdGl2aXR5OwogICAgICAgIGFycmF5PHBhaXI8aW50LGludD4sTUFYTj50ZW1wX2FjdGl2aXR5OwogICAgICAgIG1hcDxwYWlyPGludCxpbnQ+ICwgY2hhcj5hbnN3ZXI7CiAgICAgICAgcHJpbnRmKCJDYXNlICMlZDogIix0dCk7CiAgICAgICAgaW50IG47c2NhbmYoIiVkIiwmbik7CiAgICAgICAgZm9yKGludCBpPTA7aTxuOysraSl7CiAgICAgICAgICAgIGludCAmdSA9IGFjdGl2aXR5W2ldLmZpcnN0OwogICAgICAgICAgICBpbnQgJnYgPSBhY3Rpdml0eVtpXS5zZWNvbmQ7CiAgICAgICAgICAgIHNjYW5mKCIlZCVkIiwmdSwmdik7CiAgICAgICAgICAgIGRpZmZfYXJyYXlbdV0rKzsKICAgICAgICAgICAgZGlmZl9hcnJheVt2KzFdLS07CiAgICAgICAgICAgIHRlbXBfYWN0aXZpdHlbaV0gPSBhY3Rpdml0eVtpXTsKICAgICAgICB9CiAgICAgICAgZm9yKGludCBpPTE7aTw9bjsrK2kpewogICAgICAgICAgICBkaWZmX2FycmF5W2ldKz1kaWZmX2FycmF5W2ktMV07CiAgICAgICAgfQogICAgICAgIGlmKGFueV9vZihkaWZm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jb25kOwogICAgICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICAgICAgcHV0cygiU29tZXRoaW5nIGlzIFdyb25nIik7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yKGludCBpPTA7aTxuOysraSl7CiAgICAgICAgICAgICAgICBjb3V0PDxhbnN3ZXJbdGVtcF9hY3Rpdml0eVtpXV07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcHV0cygiIik7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0=