#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;
}