#include <bits/stdc++.h>
using namespace std ;
typedef long long int ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;ll o=1;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n==1)
{
ll x,y;
cin>>x>>y;
cout<<"Case #";
cout<<o;
o++;
cout<<": ";
cout<<"0 ";
cout<<x;
}
else
{
ll e[n+1],r[n+1];
ll i = 1;
while(i<=n)
{
cin>>e[i]>>r[i];
i++;
}
//Generating all subsets
long long int d;
d=pow(2,n);
long long int j;
i=0;
ll e2[50];
ll r2[50];
i=0;
while(i<=49)
{
e2[i]=0;
r2[i]=0;
i++;
}
ll max2=-1;
ll op=1e18;
ll jee=1e18;
i=0;
while(i<d)
{
j=1;
ll count=0;ll ram=1;
while(j<=n)
{
if( i & (1<<(j-1)) )
{
e2[ram]=e[j];
r2[ram]=r[j];
ram++;
count++;
}
else
{
}
j++;
}
if(count==0)
{
}
else
{
ll left = n-count ;
ll sum=e2[1];
ll i1=2;
while(i1<=ram)
{
sum=sum+e2[i1];
ll x = e2[i1];
ll jx = 1;
while(jx<=i1-1)
{
r2[jx]=r2[jx]-x;
jx++;
}
i1++;
}
//round___2...
i1=1;ll good=0;
while(i1<=ram)
{
if(r2[i1]>0)
{
good=1;
i1=1e18;
}
else
{
sum=sum+e2[i1];
ll x = e2[i1];
ll jx = i1+1 ;
while(jx<=ram)
{
r2[jx]=r2[jx]-x;
jx++;
}
}
i1++;
}
if(good==1)
{
//cout<<sum;
if(sum==max2)
{
op=min(op,left);
}
if(sum>max2)
{
max2=sum;
op=left;
}
}
else
{
jee=min(jee,left);
//cout<<"INDEFINITELY";
}
}
i++;
}
cout<<"Case #";
cout<<o;
o++;
cout<<": ";
if(jee==1e18)
{
cout<<op<<" "<<max2;
}
else
{
cout<<jee<<" ";
cout<<"INDEFINITELY";
}
}
cout<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQgOwp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CmludCBtYWluKCkKeyAgIAoJCglpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBjb3V0LnRpZShOVUxMKTsKICAgIGxsIHQ7bGwgbz0xOwogICAgY2luPj50OwogICAgd2hpbGUodC0tKQogICAgewogICAgICAgIGxsIG47CiAgICAgICAgY2luPj5uOwogICAgICAgIGlmKG49PTEpCiAgICAgICAgewogICAgICAgIAlsbCB4LHk7CiAgICAgICAgICAgIGNpbj4+eD4+eTsKICAgICAgICAgICAgY291dDw8IkNhc2UgIyI7CiAgICAgICAgICAgIGNvdXQ8PG87CiAgICAgICAgICAgIG8rKzsKICAgICAgICAgICAgY291dDw8IjogIjsKICAgICAgICAgICAgY291dDw8IjAgIjsKICAgICAgICAgICAgY291dDw8eDsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgbGwgZVtuKzFdLHJbbisxXTsKICAgICAgICAgICAgbGwgaSA9IDE7CiAgICAgICAgICAgIHdoaWxlKGk8PW4pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgCWNpbj4+ZVtpXT4+cltpXTsKICAgICAgICAgICAgICAgIGkrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgIC8vR2VuZXJhdGluZyBhbGwgc3Vic2V0cwogICAgbG9uZyBsb25nIGludCBkOwoJZD1wb3coMixuKTsKCWxvbmcgbG9uZyBpbnQgajsKCWk9MDsKCWxsIGUyWzUwXTsKICAgIGxsIHIyWzUwXTsKCWk9MDsKCXdoaWxlKGk8PTQ5KQoJewoJICAgIAoJICAgIGUyW2ldPTA7CgkgICAgcjJbaV09MDsKCSAgICBpKys7Cgl9CglsbCBtYXgyPS0xOwoJbGwgb3A9MWUxODsKCWxsIGplZT0xZTE4OwoJaT0wOwoJd2hpbGUoaTxkKQoJewoJCQoJCQoJICAgIGo9MTsgIAogICAgICAgIGxsIGNvdW50PTA7bGwgcmFtPTE7CiAgICAgICAgd2hpbGUoajw9bikKICAgICAgICB7CiAgICAgICAgCQogICAgICAgIAkKICAgIAkKICAgICAgICAKICAgICAgICAgICAgaWYoIGkgJiAoMTw8KGotMSkpICApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgZTJbcmFtXT1lW2pdOwogICAgICAgICAgICByMltyYW1dPXJbal07CiAgICAgICAgICAgIHJhbSsrOwogICAgICAgICAgICBjb3VudCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICB9CiAgICAgICAgCiAgICAgICAgCiAgICAgICAgCiAgICAgICAgaisrOwogICAgICAgIH0KCgoJCglpZihjb3VudD09MCkKCXsKCSAgICAKCX0KCWVsc2UKCXsKCQkKCSAgICBsbCBsZWZ0ID0gbi1jb3VudCA7IAogICAgICAgIGxsIHN1bT1lMlsxXTsKICAgICAgICBsbCBpMT0yOwogICAgICAgIHdoaWxlKGkxPD1yYW0pCiAgICAgICAgewogICAgICAgICAgICBzdW09c3VtK2UyW2kxXTsKICAgICAgICAgICAgbGwgeCA9IGUyW2kxXTsKICAgICAgICAgICAgbGwganggPSAxOwogICAgICAgICAgICB3aGlsZShqeDw9aTEtMSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIAkKICAgICAgICAgICAgICAgICAgICByMltqeF09cjJbanhdLXg7CiAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgangrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaTErKzsKICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICAvL3JvdW5kX19fMi4uLgogICAgICAgICAgICAKICAgICAgICBpMT0xO2xsIGdvb2Q9MDsKICAgICAgICB3aGlsZShpMTw9cmFtKQogICAgICAgIHsKICAgICAgICAJCiAgICAgICAgICAgIGlmKHIyW2kxXT4wKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBnb29kPTE7CiAgICAgICAgICAgICAgICBpMT0xZTE4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAJCiAgICAgICAgICAgICAgICBzdW09c3VtK2UyW2kxXTsKICAgICAgICAgICAgICAgIGxsIHggPSBlMltpMV07CiAgICAgICAgICAgICAgICBsbCBqeCA9IGkxKzEgOwogICAgICAgICAgICAgICAgd2hpbGUoang8PXJhbSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIAkKICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICByMltqeF09cjJbanhdLXg7CiAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICBqeCsrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaTErKzsKICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgIGlmKGdvb2Q9PTEpCiAgICAgICAgewogICAgICAgICAgICAgICAgLy9jb3V0PDxzdW07CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgaWYoc3VtPT1tYXgyKQogICAgICAgICAgICB7CiAgICAgICAgICAgIAkKICAgICAgICAgICAgICAgIG9wPW1pbihvcCxsZWZ0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZihzdW0+bWF4MikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgbWF4Mj1zdW07CiAgICAgICAgICAgICAgICBvcD1sZWZ0OwogICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAJamVlPW1pbihqZWUsbGVmdCk7CiAgICAgICAgICAgIC8vY291dDw8IklOREVGSU5JVEVMWSI7CiAgICAgICAgfQoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJICAgIAoJfQoJaSsrOwoJICAgIAoJICAgIAoJfQoJCiAgICAgICAgICAgIAogICAgY291dDw8IkNhc2UgIyI7CiAgICBjb3V0PDxvOwogICAgbysrOwogICAgY291dDw8IjogIjsKICAgIGlmKGplZT09MWUxOCkKICAgICAgICB7CiAgICAgICAgICAgICAgICBjb3V0PDxvcDw8IiAiPDxtYXgyOwogICAgICAgIH0KICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgICAgICBjb3V0PDxqZWU8PCIgIjsKICAgICAgICAgICAgICAgIGNvdXQ8PCJJTkRFRklOSVRFTFkiOwogICAgICAgIH0KICAgICAgICAgICAgCiAgICB9CiAgICAgICAgCiAgICAgICAgCiAgICAgICAgY291dDw8IlxuIjsKICAgIH0KICAgIAogICAgCiAgICAKICAgIAogICAgCiAgICAKICAgIAogICAgcmV0dXJuIDA7Cn0=