#include <iostream>
#include <algorithm>
#include <cstring>
#define Max_K 6
using namespace std;
struct Student
{int id;//准考证号int score_of_problem[Max_K];//每道题的分数int num_solved;//AC的题目数bool flag;//是否有通过了编译的提交int total_score;//总分
}student[100010];bool cmp(Student a,Student b)
{if(a.flag != b.flag) return a.flag>b.flag;//需要输出的学生排在前面else if(a.total_score!=b.total_score) return a.total_score>b.total_score;else if(a.num_solved!=b.num_solved) return a.num_solved>b.num_solved;else return a.id<b.id;
}
int N,K,M,perfectScore[Max_K];void init()//初始化
{for(int j=1;j<=N;j++){student[j].id = j;student[j].total_score = 0;student[j].num_solved=0;student[j].flag = false;memset(student[j].score_of_problem,-1,sizeof(student[j].score_of_problem));//每道题目的得分初始化为1}
}int main()
{scanf("%d %d %d",&N,&K,&M);init();for(int i = 1;i<=K;i++){scanf("%d",&perfectScore[i]);}int tmpId,tmpProblem,tmpScore;for(int i = 0;i<M;i++){scanf("%d %d %d",&tmpId,&tmpProblem,&tmpScore);if(tmpScore!= -1){student[tmpId].flag = true;}if(tmpScore == -1 &&student[tmpId].score_of_problem[tmpProblem] == -1){student[tmpId].score_of_problem[tmpProblem] = 0;}if(tmpScore==perfectScore[tmpProblem]&&student[tmpId].score_of_problem[tmpProblem]<perfectScore[tmpProblem])//某道题第一次获得满分,完美解题数加一{student[tmpId].num_solved++;}if(tmpScore>student[tmpId].score_of_problem[tmpProblem])//获得更高分数,修改对应的分数{student[tmpId].score_of_problem[tmpProblem] = tmpScore;}}for(int i = 1;i<=N;i++)for(int j = 1;j<=K;j++){if(student[i].score_of_problem[j]!=-1)student[i].total_score += student[i].score_of_problem[j];}sort(student+1,student+N+1,cmp);int r = 1; //用于排名,当前为1;for(int i = 1;i<=N && student[i].flag==true;i++){if(i>1 && student[i].total_score != student[i-1].total_score)r = i;//当考生分数低于前一个考生的分数,则其排名为在该考生前面的考生的总人数printf("%d %05d %d",r,student[i].id,student[i].total_score);for(int j = 1;j<=K;j++){if(student[i].score_of_problem[j] == -1)printf(" -");elseprintf(" %d",student[i].score_of_problem[j]);}printf("\n");}return 0;
}