#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,k;
struct Student
{
string id;
int scores[6]={-2,-2,-2,-2,-2,-2};
int total_score=0;
int cnt=0,sum=0;
int rank;
bool operator<(const Student& t)const
{
if(total_score!=t.total_score)return total_score>t.total_score;
if(sum!=t.sum)return sum>t.sum;
return id<t.id;
}
};
vector<Student>grades;
unordered_map<string,Student>students;
int main()
{
scanf("%d %d %d",&n,&k,&m);
int a[k+10];
for(int i=1;i<=k;++i)scanf("%d",&a[i]);
for(int i=0;i<m;++i)
{
char user_id[10];
int problem_id,score;
scanf("%s %d %d",user_id,&problem_id,&score);
students[user_id].id=user_id;
if(students[user_id].scores[problem_id]<score)
{
if(score==-1)students[user_id].scores[problem_id]=0;
else students[user_id].scores[problem_id]=score,students[user_id].cnt++;
if(score==a[problem_id])students[user_id].sum++;
}
}
char s[n+10][10];
for(int i=1;i<=n;++i)sprintf(s[i],"%05d",i);
for(int i=1;i<=n;++i)if(students.count(s[i]))grades.push_back(students[s[i]]);
for(int i=0;i<grades.size();++i)
{
for(int j=1;j<=k;++j)
if(grades[i].scores[j]!=-1&&grades[i].scores[j]!=-2)
{
grades[i].total_score+=grades[i].scores[j];
}
}
sort(grades.begin(),grades.end());
for(int i=0;i<grades.size();++i)
if(!i||grades[i].total_score!=grades[i-1].total_score)grades[i].rank=i+1;
else grades[i].rank=grades[i-1].rank;
for(int i=0;i<grades.size();++i)
{
if(grades[i].cnt!=0)
{
printf("%d %s %d",grades[i].rank,grades[i].id.c_str(),grades[i].total_score);
for(int j=1;j<=k;++j)
if(grades[i].scores[j]!=-1&&grades[i].scores[j]!=-2)printf(" %d",grades[i].scores[j]);
else printf(" -");
printf("\n");
}
}
return 0;
}