// Arup Guha
// 8/4/2026
// Solution to 1990 UCF HS Programming Contest Problem: Motocross Scoring

import java.util.*;

public class motox {
	
	// list[i] will store rider with number i.
	public static rider[] list;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		
		// This should cover it...
		list = new rider[100];
		Arrays.fill(list, null);
		
		// We have to read in line by line.
		int n = Integer.parseInt(stdin.nextLine());
		for (int i=0; i<n; i++) {
		
			// Set up our tokenizer.
			StringTokenizer tok = new StringTokenizer(stdin.nextLine(),",");
			int id = Integer.parseInt(tok.nextToken());
			String name = tok.nextToken();
			String bikeclass = tok.nextToken();
			int pts = Integer.parseInt(tok.nextToken());
			list[id] = new rider(name, bikeclass, pts);
		}
		
		// Now, to all of the races!
		while (stdin.hasNext()) {
		
			// Get race name and how many individual races.
			String raceName = stdin.nextLine();
			int numRaces = Integer.parseInt(stdin.nextLine());
			
			// Make a race object.
			race tmp = new race();
			
			// Now process races.
			for (int i=0; i<numRaces; i++) {
			
				// Get all of the race data!
				String data = stdin.nextLine();
				tmp.addCategory(data);
			}
			
			// Now update the points.
			tmp.updatePts(list);
			
			// Header for race.
			System.out.println("Final standings for event "+raceName);
			
			// Since I need the names, I can't overload toString in race...
			printRace(tmp);
		}
		
		// Final Driver standings.
		System.out.println("                                  *** Final rider report ***");
		System.out.println();
		System.out.println("                              Current        Total          Eligible");
		System.out.println("Num            Name           Class          Points         Class");
		System.out.println("---            ----           -------        ------         --------");
		for (int i=0; i<100; i++) {
			if (list[i] == null) continue;
			System.out.printf("%-15d%-15s%d%c           %-5d          %s\n", i, list[i].name, list[i].disp, list[i].curClass, list[i].points, list[i].getTopClass());
		}
	}
	
	// Prints the results of race r.
	public static void printRace(race r) {
		
		System.out.println(" Class                  125                      250                      500");
		System.out.println(" -----               ---------                ---------                ---------");
		
		// This part is reasonably clean, rest isn't.
		for (int i=0; i< r.results.length; i++) {
			
			// We have to go in order of place.
			for (int place=0; place<5; place++) {
				
				// Annoying.
				if (place == 0) 
					System.out.print(rider.GROUP[i]+" "+(place+1)+"          ");
				else
					System.out.print("  "+(place+1)+"          ");
				
				// j is the index into the type of race, 125, 250 or 500.
				for (int j=0; j<3; j++) {
					
					// Weird DID NOT RUN case.
					if (r.results[i][j] == null) {
						if (place == 0) System.out.print("           DID           ");
						else if (place == 2) System.out.print("           NOT           ");
						else if (place == 4) System.out.print("           RUN           ");
						else System.out.print("                         ");
					}
					
					else if (r.results[i][j][place] != -1) {
						int id = r.results[i][j][place];
						printCenter(25, id, list[id].name); 
					}
					else
						System.out.print("                         ");
				}
				
				// New line for 1 to 5 places.
				System.out.println();
			}
			
			// Extra blank line after 5th place for a class.
			System.out.println();
		}
	}
	
	// This is annoying but I think it's closest to what the sample output appears.
	public static void printCenter(int len, int id, String name) {
		
		// Make string to print and compute amount of padding on each side.
		String toPrint = name+"("+id+")";
		int padRight = (len-toPrint.length())/2;
		int padLeft = len-toPrint.length()-padRight;
		
		// Print it.
		for (int i=0; i<padLeft; i++) System.out.print(" ");
		System.out.print(toPrint);
		for (int i=0; i<padRight; i++) System.out.print(" ");
	}
}

class race {
	
	public int[][][] results;
	
	public race() {
	
		// Initially we set these all to null.
		results = new int[4][3][];
		for (int i=0; i<4; i++)
			for (int j=0; j<3; j++)
				results[i][j] = null;
	}
	
	// Returns the index corresponding to the class with letter c.
	public static int getClass(char c) {
		if (c == 'C') return 0;
		if (c == 'B') return 1;
		if (c == 'A') return 2;
		return 3;
	}
	
	public static int getDisp(int disp) {
		if (disp == 125) return 0;
		if (disp == 250) return 1;
		return 2;
	}
	
	public void addCategory(String data) {
	
		StringTokenizer tok = new StringTokenizer(data, ",");
		String thisCat = tok.nextToken();
		int row = getClass(thisCat.charAt(3));
		int col = getDisp(Integer.parseInt(thisCat.substring(0,3)));
		
		// Add this array so we know the race occurred.
		results[row][col] = new int[5];
		Arrays.fill(results[row][col], -1);
		
		// Easy does it!
		int idx = 0;
		while (tok.hasMoreTokens() && idx < 5) 
			results[row][col][idx++] = Integer.parseInt(tok.nextToken());
	}
	
	public void updatePts(rider[] list) {
	
		// Go through everything.
		for (int i=0; i<4; i++) {
			for (int j=0; j<3; j++) {
			
				// Skip it.
				if (results[i][j] == null) continue;
			
				// Go through all the placements.
				for (int k=0; k<5; k++) {
				
					// Get out no one else completed race.
					if (results[i][j][k] == -1) break;
					
					// Here we add the points.
					list[results[i][j][k]].addPts(k);
				}
			}
		}
	}

}

class rider {

	// Points for each place.
	final public static int[] POINTS_RACE = {20,10,5,2,1};
	
	final public static char[] GROUP = {'C','B','A','P'};
	
	// Requirements to move up.
	final public static int[][] LEVELS = {{25,60,95},{30,70,110},{40,90,150}};
	
	public String name;
	public int disp;
	public char curClass;
	public int points;
	
	public rider(String n, String bike, int curPts) {
		name = n;
		disp = Integer.parseInt(bike.substring(0,3));
		curClass = bike.charAt(3);
		points = curPts;
	}
	
	public void addPts(int position) {
		if (position >= 5) return;
		points += POINTS_RACE[position];
	}
	
	public String getTopClass() {
		
		// Index into levels array.
		int dIdx = race.getDisp(disp);
		
		// See the highest level you can make it for your displacement.
		int idx = 0;
		while (idx < 3 && points >= LEVELS[dIdx][idx]) idx++;
		
		// This is what we print.
		return ""+disp+(GROUP[idx]);
	}

}