#include<cstdio>
#include<algorithm>
using namespace std;
/*
(1)没能过编译器的话就是-1,过了编译器至少有0分。
(2)若没有一道题能过编译器的话或者,没有提交任何
题目的人不出现在排名中。要想上排名至少要有一
题要过编译器,哪怕只有0分。
(3)按总分由高到低排名,完美解答题目的个数,id从
小到大
(4)没有提交为-2,提交了没过编译器为-1,提交了过了
编译器为>=0。
(5)没过编译器输出为0分。
*/
/*
要注意一种数据,就是如果排序时不让可输出的排在前面的话,有可能有两个两个人总分都是
0分(因为初始化总分为0),但是排第一名的是不能输出的,但是排第二名的是可输出的。
对于这种情况只要在cmp中加上 if(a.show!=b.show) return a.show>b.show; 即可。
*/
struct student{
int id;
int s[6];
int perfect;
int show,total;
}stu[10010];
bool cmp(student a, student b)
{
if(a.show!=b.show) return a.show>b.show;
else if(a.total!=b.total) return a.total>b.total;
else if(a.perfect!=b.perfect) return a.perfect>b.perfect;
else return a.id<b.id;
}
int main()
{
int n,k,m;
scanf("%d%d%d",&n,&k,&m);
int fullMark[k+1];
for(int i=1; i<=k; i++){
scanf("%d",&fullMark[i]);
}
for(int i=1; i<=n; i++){
stu[i].show = 0;
stu[i].total = 0;
stu[i].perfect = 0;
for(int j=0; j<6; j++){
stu[i].s[j] = -2;
}
}
for(int i=0; i<m; i++){
int num,score,id;
scanf("%d%d%d",&id,&num,&score);
stu[id].id = id;
if(stu[id].s[num]<score)
stu[id].s[num] = score;
}
for(int i=1; i<=n; i++){
for(int j=1; j<=k; j++){
if(stu[i].s[j]>=0){
stu[i].show = 1;
break;
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=k; j++){
if(stu[i].s[j]==fullMark[j]){
stu[i].perfect++;
}
if(stu[i].s[j]>=0)
stu[i].total+=stu[i].s[j];
}
}
sort(stu+1,stu+n+1,cmp);
int r = 1;
printf("%d %05d %d",r,stu[1].id,stu[1].total);
for(int j=1; j<=k; j++){
if(stu[1].s[j]==-2)
printf(" -");
else if(stu[1].s[j]==-1)
printf(" 0");
else printf(" %d",stu[1].s[j]);
}
printf("\n");
for(int i=2; i<=n; i++){
if(stu[i].show==false) continue;
if(stu[i].total!=stu[i-1].total)
r=i;
printf("%d %05d %d",r,stu[i].id,stu[i].total);
for(int j=1; j<=k; j++){
if(stu[i].s[j]==-2)
printf(" -");
else if(stu[i].s[j]==-1)
printf(" 0");
else printf(" %d",stu[i].s[j]);
}
printf("\n");
}
}