Go: // You Are the Judge(審判は君だ！)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2400&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Team struct {
	TID         int
	Accepted    int
	WrongAnswer map[int]int
	Penalty     int
}

type Teams []Team

func (t Teams) Len() int      { return len(t) }
func (t Teams) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t Teams) Less(i, j int) bool {
	// より多くの問題を解いたチームは順位が上になる
	if t[i].Accepted > t[j].Accepted {
		return true
	} else if t[i].Accepted == t[j].Accepted {
		// 解いた問題が同じ場合、ペナルティの少ないチームのほうが順位が上になる
		if t[i].Penalty < t[j].Penalty {
			return true
		} else if t[i].Penalty == t[j].Penalty {
			// 解いた問題もペナルティも同じ場合、チーム番号が小さいほうのチームが順位が上になる
			if t[i].TID < t[j].TID {
				return true
			}
		}
	}
	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		t, p, r := nextInt(sc), nextInt(sc), nextInt(sc)
		if t == 0 && p == 0 && r == 0 {
			break
		}

		teams := []Team{}
		for tID := 0; tID < t; tID++ {
			teams = append(teams, Team{tID + 1, 0, map[int]int{}, 0})
		}

		for i := 0; i < r; i++ {
			tID, pID, time, message := nextInt(sc), nextInt(sc), nextInt(sc), nextString(sc)
			tID--

			if message == "CORRECT" {
				teams[tID].Accepted++
				wa, _ := teams[tID].WrongAnswer[pID]
				teams[tID].Penalty += wa*1200 + time
			} else {
				teams[tID].WrongAnswer[pID]++
			}
		}

		sort.Sort(Teams(teams))

		for _, team := range teams {
			fmt.Println(team.TID, team.Accepted, team.Penalty)
		}
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef long long ll;

class team {
public:
    int accept_count;
    int total_time;
    int wrong_answer_count[11];
    int team_id;
    void set_team_id(int id) {
        team_id = id;

    }
    void query(int tId, int pId, int time_, string message) {
        if(message == "WRONG") {
            wrong_answer_count[pId]++;
        }
        else {
            accept_count++;
            total_time += time_;
            total_time += 1200 * wrong_answer_count[pId];
        }

    }
    bool operator< (const team& t) const {
        if(this->accept_count != t.accept_count) {
            return this->accept_count > t.accept_count;
        }
        if(this->total_time != t.total_time) {
            return this->total_time < t.total_time;
        }


        return this->team_id < t.team_id;
    }
};

int T,P,R;

void solve() {
    vector<team> teams(T);
    rep(i,teams.size()) {
        teams[i].set_team_id(i+1);
    }
    rep(i,R) {
        int a,b,c;
        string d;
        cin>>a>>b>>c>>d;
        teams[a-1].query(a,b,c,d);
    }
    sort(all(teams));

    rep(i,teams.size()) {
        cout<<teams[i].team_id<<" "<<teams[i].accept_count<<" "<<teams[i].total_time<<endl;
    }
}
int main() {
    while(cin>>T>>P>>R) {
        if(T+P+R==0) break;
        solve();

    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int t,p,r;
int tid[510],pid[510],tim[510];
string mes[510];
int clear[55][15];
struct team{
	int no;
	int cor;
	int pen;
	

};
bool operator<(team& b,team& a){
	if(b.cor!=a.cor){
		return b.cor>a.cor;
	}else if(b.pen!=a.pen){
		return b.pen<a.pen;
	}else{
		return b.no<a.no;
	}
}
int main(){
	while(1){
		cin>>t>>p>>r;
		if(t==0&&p==0&&r==0)break;
		REP(i,55)
			REP(j,15)
			clear[i][j]=0;
		team te[55];
		for(int i=1;i<=t;i++){
			te[i]=team{i,0,0};
		}
		REP(i,r){
			cin>>tid[i]>>pid[i]>>tim[i]>>mes[i];
			if(mes[i]=="CORRECT")clear[tid[i]][pid[i]]=1;
		}
		REP(i,r){
			if(mes[i]=="CORRECT"){
				te[tid[i]].cor++;
				te[tid[i]].pen+=tim[i];
			}else if(mes[i]=="WRONG"&&clear[tid[i]][pid[i]]==1){
				te[tid[i]].pen+=1200;
			}
		}
		
		sort(te+1,te+t+1);
		for(int i=1;i<=t;i++){
			cout<<te[i].no<<" "<<te[i].cor<<" "<<te[i].pen<<endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	int t,p,r;
	string mestype[2] = {"WRONG","CORRECT"};
	while(true){
		cin >> t >> p >> r;
		if( !t && !p && !r){
			break;
		}
		int teams_no[50];
		int teams[50]; // 点数
		int teams_c[50];
		int teams_p[50]; // ペナルティ
		int teams_w[10][50]; // ><;
		for(int i = 0; i < t; i++){
			teams[i] = 0;
			teams_c[i] = 0;
			teams_p[i] = 0;
			teams_no[i] = i + 1;
		}
		for(int i = 0; i < p; i++){
			for(int j = 0; j < t; j++){
				teams_w[i][j] = 0;
			}
		}
		
		
		int teams_in;
		for(int i = 0; i < r; i++){
			int pno, time;
			string mes;
			cin >> teams_in >> pno >> time;
			cin >> mes;
			if(mes == mestype[0]){
				teams_w[pno - 1][teams_in - 1]++;
			}
			else{
				teams_c[teams_in - 1]++;
				teams_p[teams_in - 1] += teams_w[pno - 1][teams_in - 1] * 1200 + time;
				teams[teams_in - 1] += 10000000 - teams_p[teams_in - 1];
			}
		}
		
		for(int i = 0 ; i < t - 1; i++){
			for(int j = i + 1 ; j < t; j++){
				if(teams[i] < teams[j]){
					swap(teams[i], teams[j]);	
					swap(teams_no[i], teams_no[j]);
					swap(teams_p[i], teams_p[j]);
					swap(teams_c[i], teams_c[j]);
				}
			}
		}
		for(int i = 0 ; i < t ; i++){
			for(int j = 0 ; j < t; j++){
				if(teams[i] == teams[j]){
				if(teams_p[i] == teams_p[j]){
					if(teams_no[i] < teams_no[j]){
						swap(teams[i], teams[j]);	
						swap(teams_no[i], teams_no[j]);
						swap(teams_p[i], teams_p[j]);	
						swap(teams_c[i], teams_c[j]);
					}	
				}
				}
			}
		}
		for(int i = 0; i < t; i++){
			printf("%d %d %d\n", teams_no[i], teams_c[i], teams_p[i]);
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

typedef struct {int id, solved, penalty;} Team;

int compare(const void *a, const void *b) {
	const Team ta = *(Team *)a, tb = *(Team *)b;

	if (ta.solved != tb.solved)
		return tb.solved - ta.solved;
	if (ta.penalty != tb.penalty)
		return ta.penalty - tb.penalty;
	return ta.id - tb.id;
}

int main(void) {
	int i;
	int t, p, r;

	while (scanf("%d %d %d", &t, &p, &r), t) {
		Team team[50] = {0};
		int wrong[50][10] = {0};

		for (i = 0; i < t; i++)
			team[i].id = i + 1;

		for (i = 0; i < r; i++) {
			int tid, pid, t;
			char mes[10];

			scanf("%d %d %d %s", &tid, &pid, &t, mes);
			tid--;
			pid--;

			if (mes[0] == 'C') {
				team[tid].solved++;
				team[tid].penalty += wrong[tid][pid] * 1200 + t;
			} else
				wrong[tid][pid]++;
		}

		qsort(team, t, sizeof(Team), &compare);

		for (i = 0; i < t; i++)
			printf("%d %d %d\n", team[i].id, team[i].solved, team[i].penalty);
	}

	return 0;
}