#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;
const int K = 6;
int n, k, m;
int p_score[K];
struct Student
{
string id;
int grade[K]={-2};
int total=0, cnt=0;
};
bool cmp(Student a,Student b)
{
if (a.total != b.total) return a.total > b.total;
if (a.cnt != b.cnt) return a.cnt > b.cnt;
return a.id < b.id;
}
Student calc(Student a)
{
for (int i = 1; i <= k; i ++ )
{
a.total += max(0, a.grade[i]);
if (a.grade[i] == p_score[i]) a.cnt ++ ;
}
return a;
}
bool has_submit(Student a)
{
for (int i = 1; i <= k; i ++ )
if (a.grade[i] >= 0)
return true;
return false;
}
int main()
{
unordered_map<string, Student> students;
scanf("%d%d%d", &n, &k, &m);
for (int i = 1; i <= k; i ++ ) scanf("%d", &p_score[i]);
while (m -- )
{
string u_id;
char u_id_s[6];
int p_id, grade;
scanf("%s%d%d", u_id_s, &p_id, &grade);
u_id = u_id_s;
if (students.count(u_id) == 0)
{
Student a;
a.id=u_id;
for(int i=0;i<K;i++) a.grade[i]=-2;
a.cnt=0;
a.total=0;
students[u_id]=a;
}
students[u_id].grade[p_id] = max(students[u_id].grade[p_id], grade);
}
vector<Student> res;
for(auto& item: students)
{
auto& s = item.second;
if (has_submit(s))
{
s=calc(s);
res.push_back(s);
}
}
sort(res.begin(), res.end(),cmp);
for (int i = 0, rank = 1; i < res.size(); i ++ )
{
if(res[i].total==0) continue;
if (i && res[i].total != res[i - 1].total) rank = i + 1;
printf("%d %s %d", rank, res[i].id.c_str(), res[i].total);
for (int j = 1; j <= k; j ++ )
if (res[i].grade[j] == -2) printf(" -");
else printf(" %d", max(0, res[i].grade[j]));
cout<<endl;
}
return 0;
}