extern crate core;

use std::str::FromStr;
use std::fmt;
use std::cmp::Ordering;
use std::fmt::{Display, Error, Formatter};
use std::ops::Range;

struct Istream {
    line: Vec<String>,
    position: usize
}

macro_rules! iterate {
    ($generator:expr; $count:expr; $typ:ty) => {{
        let mut vec = Vec::<$typ>::with_capacity($count);
        for i in 0 .. $count {
            vec.push($generator);
        }
        vec
    }}
}
macro_rules! yields {
    ($count:expr; $block:block) => {{
        let mut vec = Vec::with_capacity($count);
        for _ in 0 .. $count {
            vec.push($block);
        }
        vec
    }}
}
type Parse<T: FromStr> = Result<T, T::Err>;
impl Istream {
    fn new() -> Istream {
        Istream {line:vec![], position: 0}
    }
    fn read_word(&mut self) -> &String {
        if self.position == self.line.len() {
            let mut line= String::new();
            std::io::stdin().read_line(&mut line).ok();
            self.line = line.split_whitespace().map(|x|x.to_string()).collect();
            self.position = 0
        }
        let result = &self.line[self.position];
        self.position += 1;
        result
    }
    fn read(&mut self) -> String {
        self.read_word().to_string()
    }
    fn get<T: FromStr>(&mut self) -> T {self.read_word().parse().ok().unwrap()}
    fn read_usize(&mut self) -> usize {self.get()}
    fn read_int(&mut self) -> i32 {self.get()}
    fn read_long(&mut self) -> i64 {self.get()}
    fn read_double(&mut self) -> f64 {self.get()}
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>();
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>();
    };
}

macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! assign_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        assign_all!(iter; $($n:$t),*);
    };
    ($iter: expr; ) => {};
    ($iter:expr; $n:ident:$t:ty) => {
        let $n: $t = $iter.next().unwrap().parse().ok().unwrap();
    };
    ($iter: expr; $n:ident:$t:ty, $($m:ident:$u:ty),*) => {
        let $n: $t = $iter.next().unwrap().parse().ok().unwrap();
        assign_all!($iter; $($m:$u),*);
    };
}
macro_rules! repeat {
    ($count:expr; $($statement:tt)+) => {
        for _ in 0 .. $count {
            $($statement)*
        }
    };
}

#[derive(PartialEq, Eq)]
struct TeamScore {
    team_id: usize,
    solved: i32,
    penalty: i32,
}
impl TeamScore {
    fn new(id: usize, submit_time: &Vec<i32>, wrong_answer_count: &Vec<i32>) -> TeamScore {
        let mut solved = 0;
        let mut penalty = 0;
        for i in 0..submit_time.len() {
            if submit_time[i] != 0 {
                solved += 1;
                penalty += submit_time[i] + 1200 * wrong_answer_count[i];
            }
        }
        TeamScore{team_id: id, solved: solved, penalty: penalty}
    }
}
impl Ord for TeamScore {
    fn cmp(&self, other: &Self) -> Ordering {
        if self.solved == other.solved {
            if self.penalty == other.penalty {
                self.team_id.cmp(&other.team_id)
            }else {
                self.penalty.cmp(&other.penalty)
            }
        }else {
            other.solved.cmp(&self.solved)
        }
    }
}
impl PartialOrd for TeamScore {
    fn partial_cmp(&self, other: &TeamScore) -> Option<Ordering> {
        Some(self.cmp(&other))
    }
}
fn tabulate<F, R>(count: usize, mut generator: F) -> Vec<R> where F : FnMut(usize) -> R {
    let mut result = Vec::<R>::with_capacity(count);
    for f in 0 .. count {
        result.push(generator(f));
    }
    result
}
impl Display for TeamScore {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        write!(f, "{} {} {}", self.team_id, self.solved, self.penalty)
    }
}
fn main() {
    loop {
        let_all!(t: usize, p: usize, r: usize);
        if t == 0 && p == 0 && r == 0 {
            break
        }
        let mut submit_time = yields![t; {vec![0; p]}];
        let mut wrong_answer_count = yields![t; {vec![0; p]}];
        for _ in 0 .. r {
            let_all!(t_id: usize, p_id: usize, time: i32, message: String);
            match &message[..] {
                "CORRECT" => {
                    submit_time[t_id - 1][p_id - 1] = time;
                },
                "WRONG" => {
                    wrong_answer_count[t_id - 1][p_id - 1] += 1;
                },
                _ => unreachable!()
            }
        }
        let mut team = tabulate(t, |id| {TeamScore::new(id + 1, &submit_time[id], &wrong_answer_count[id])});
        team.sort();
        for t in team {
            println!("{}", t);
        }
    }
}


Measured memory_bytes: 5060