An automated classroom assessment system determines a class's overall performance based on a string of individual student grades. The grades are 'A', 'B', 'C', 'D', 'E', 'F', with a strict precedence order: A > B > C > D > E > F.
The final grade is determined by comparing the total count of high-ranking grades against the total count of low-ranking grades.
1) High Group: Consists of grades 'A', 'B', and 'C'.
2) Low Group: Consists of grades 'D', 'E', and 'F'.
First, calculate the total score for each group:
high_score = count('A') + count('B') + count('C')
low_score = count('D') + count('E') + count('F')
The final dominant grade is determined by the following rules:
If high_score > low_score, the winner is the highest-ranking grade that is present in the High Group (check for 'A' first, then 'B', then 'C').
If low_score > high_score, the winner is the highest-ranking grade that is present in the Low Group (check for 'D' first, then 'E', then 'F').
If high_score == low_score (a tie), the winner is the highest-ranking grade present in the entire class.
Your task is to implement a function that takes the string of grades and returns the single character representing the final dominant grade.
Input Format:
The first line contains a single integer T, the number of test cases.
Each of the next T lines contains a single string grades.
Output Format:
For each test case, print a single character representing the final dominant grade on a new line.