#include <bits/stdc++.h>
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
using namespace std;
typedef long long LL;
const int maxn=2e5+1;

int n;
LL gs[maxn];
LL ans[maxn],sub[maxn];
void solve() {
	unsigned long long bits=0;
	unsigned long long ww=1ull<<63;
	int i;
	for (i=1e5;i>=0;i--) {
		if (bits&ww) break; //
		bits<<=1;

		if (gs[i]) {
			if (bits<=gs[i]) bits=gs[i]&1;
			else bits-=gs[i];
		}
		//if (i<=3) cout<<i<<" "<<bits<<" "<<gs[i]<<endl;
	}
	
	for (int j=1;bits;j++,bits>>=1)
		ans[i+j]=bits&1;

	for (;i>=0;i--)
		if (gs[i]) sub[i]=gs[i];

	LL jinwei=0;
	for (int i=0;i<=100000;i++) {
		sub[i]+=jinwei;
		jinwei=sub[i]/2; sub[i]&=1;
	}

	LL jw=0;
	for (int i=0;i<=100000;i++) {
		ans[i]-=jw+sub[i];
		jw=0;
		while (ans[i]<0) ans[i]+=2,jw++;
	}
	//cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;/**/
}
int main() {
	int T; scanf("%d",&T);
	for (int tt=1;T--;tt++) {
		scanf("%d",&n);
		FOR (i,0,100000) gs[i]=ans[i]=sub[i]=0;

		for (int i=1,a,x;i<=n;i++) {
			scanf("%d%d",&a,&x);
			gs[a]+=x;
		}


		solve();

		bool flag=0;
		printf("Case #%d: ",tt);
		for (int i=1e5;i>=0;i--) {
			if (ans[i]) {
				for (int j=i;j>=0;j--) printf("%lld",ans[j]);
				puts("");
				flag=1;
				break;
			}
		}
		if (!flag) puts("0");/**/
	}
	return 0;
}
