#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<char,int> &a, 
              const pair<char,int> &b) 
{ 
    return (a.second < b.second); 
} 
int main(){
	int t;
	cin>>t;
	for(int x=1;x<=t;x++){
		int n;
		cin>>n;
		vector<pair<pair<int,int>,int>> sched;
		int start,finish;
		string ans="";
		vector<pair<char,int>> res(n);
		for(int i=0;i<n;i++){
			cin>>start>>finish;
			sched.push_back({{finish,start},i});
		}
		//sorting according to finish time
		sort(sched.begin(),sched.end());
		
		//selecting first activity assigning it to C
		res[0].first='C';
		res[0].second=sched[0].second;
		int Cfree,Jfree;
		Cfree=sched[0].first.first;
		Jfree=0;
		bool impossible=false;
		
		for(int i=1;i<n;i++){
			//TRY TO ASSIGN TO SAME PERSON
			//IF FAILED,THEN ONLY SHIFT to OTHER
			//IF THAT ALSO FAILED RETURN IMP:

			//trying to give to prev person
			if(res[i-1].first=='C'){
				if(Cfree<=sched[i].first.second){
					res[i].first='C';
					Cfree=sched[i].first.first;
					res[i].second=sched[i].second;

				}
				else if(Jfree<=sched[i].first.second){
					res[i].first='J';
					Jfree=sched[i].first.first;
					res[i].second=sched[i].second;
				}
				else{
					cout<<"Case #"<<x<<": IMPOSSIBLE\n";
					impossible=true;
					continue;
				}

			}

			if(res[i-1].first=='J'){
				if(Jfree<=sched[i].first.second){
					res[i].first='J';
					Jfree=sched[i].first.first;
					res[i].second=sched[i].second;
				}
				else if( Cfree<=sched[i].first.second){
					res[i].first='C';
					Cfree=sched[i].first.first;
					res[i].second=sched[i].second;
				}
				else{
					cout<<"Case #"<<x<<": IMPOSSIBLE\n";
					impossible=true;
					continue;
				}

			}
		}
		sort(res.begin(), res.end(), sortbysec); 
		for(int i=0;i<n;i++){
			ans=ans+res[i].first;
		}

		if(!(impossible)){
			cout<<"Case #"<<x<<": "<<ans<<"\n";
		}









	}







	return 0;
}