#include <bits/stdc++.h>
using namespace std ;
int main ()
{
int a[100] , j ,i ,t ,x ,b ,min ;
double v ,sum ;
cin>>t ;
for (i=1 ; i<=t ; i++)
{
sum=0 ;
min=20 ;
x =0 ;
for (j=0 ; j<7 ; j++)
{
cin>>b ;
a[j] = b ;
if (j<4) sum=sum+a[j] ;
if (j>3)
{
x=x+a[j] ;
if (min>=a[j]) min=a[j] ;
}
}
x=x-min ;
v= x/2.00 ;
sum = sum+v ;
if (sum>=90.0) cout<<"Case"<<" "<<i<<":"<<" "<<"A"<<endl;
else if (sum>=80.0 && sum<90.0) cout<<"Case"<<" "<<i<<":"<<" "<<"B"<<endl;
else if (sum>=70.0 && sum<80.0) cout<<"Case"<<" "<<i<<":"<<" "<<"C"<<endl;
else if (sum>=60.0 && sum<70.0) cout<<"Case"<<" "<<i<<":"<<" "<<"D"<<endl;
else if ( sum<60.0) cout<<"Case"<<" "<<i<<":"<<" "<<"F"<<endl;
}
return 0 ;
}
using namespace std ;
int main ()
{
int a[100] , j ,i ,t ,x ,b ,min ;
double v ,sum ;
cin>>t ;
for (i=1 ; i<=t ; i++)
{
sum=0 ;
min=20 ;
x =0 ;
for (j=0 ; j<7 ; j++)
{
cin>>b ;
a[j] = b ;
if (j<4) sum=sum+a[j] ;
if (j>3)
{
x=x+a[j] ;
if (min>=a[j]) min=a[j] ;
}
}
x=x-min ;
v= x/2.00 ;
sum = sum+v ;
if (sum>=90.0) cout<<"Case"<<" "<<i<<":"<<" "<<"A"<<endl;
else if (sum>=80.0 && sum<90.0) cout<<"Case"<<" "<<i<<":"<<" "<<"B"<<endl;
else if (sum>=70.0 && sum<80.0) cout<<"Case"<<" "<<i<<":"<<" "<<"C"<<endl;
else if (sum>=60.0 && sum<70.0) cout<<"Case"<<" "<<i<<":"<<" "<<"D"<<endl;
else if ( sum<60.0) cout<<"Case"<<" "<<i<<":"<<" "<<"F"<<endl;
}
return 0 ;
}