1. 

/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Problem: 11777 - Automate The Grades
* Method: ad hoc
* Accepted: 0.196
* @author Evgeni Pavlidis
*
*/

import java.io.*;
import java.util.*;

class Main {

public static void main(String...args)
{
Scanner scanner = new Scanner(System.in);
double sum;
int a,b,c, tmp;
char output;
double EPSILON = 0.000001;

int testCases = scanner.nextInt();
for(int tc = 1; tc <= testCases; tc++)
{
sum = scanner.nextInt();// * 0.2;
sum += scanner.nextInt();// * 0.2;
sum += scanner.nextInt();// * 0.3;
sum += scanner.nextInt();// * 0.1;
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
tmp = a + b + c;
a = Math.min(Math.min(a,b), c);
tmp -= a;
sum += tmp/2;// * 0.2;
if(sum > 90 - EPSILON)
output = 'A';
else if ( sum > 80 - EPSILON)
output = 'B';
else if ( sum > 70 - EPSILON)
output = 'C';
else if ( sum > 60 - EPSILON)
output = 'D';
else
output = 'F';

System.out.println("Case " + tc + ": " + output);
}
}
}