public static void main(String[] args) throws Throwable {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder( );
		int N = Integer.parseInt(in.readLine());
		in.readLine();
		for (int i = 0; i < N; i++) {
			score = new TreeMap<Integer,int[]>();
			solved = new TreeMap<Integer, boolean[]>();
			penales = new TreeMap<Integer, int[]>();
			for (String line; (line = in.readLine())!=null && line.length()>0;) {
				StringTokenizer st = new StringTokenizer(line);
				int team = Integer.parseInt(st.nextToken())-1;
				int penalPosition = Integer.parseInt(st.nextToken())-1;
				int valuePosition = Integer.parseInt(st.nextToken());
				char judge = st.nextToken().trim().charAt(0);
//				if( judge ==  'C' || judge == 'I' ){
					int[] penalties;
					boolean[] solve;
					int[] cantPenales;
					if( !score.containsKey(team) ){
						penalties = new int[10];
						solve = new boolean[9];
						cantPenales = new int[9];
					}
					else{
						penalties = score.get(team);
						solve = solved.get(team);
						cantPenales = penales.get(team);
					}
					if( judge == 'I' && !solve[penalPosition]){
						cantPenales[penalPosition] += 1;
					}else if( judge== 'C' && !solve[penalPosition] ){
						penalties[penalPosition] += valuePosition; 
						penalties[penalties.length-1]+=valuePosition;
						solve[penalPosition]=true;
					}
					score.put(team, penalties);
					solved.put(team, solve);
					penales.put(team, cantPenales);
				}
//			}
			solve( );
			if( i < N-1 )
				sb.append("\n");
		}
		System.out.print(new String(sb));
	}