/**
* author: Binoy Barman
* created: 2024-12-10 16:11:18
**/
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifdef LOCAL
#include "debug/whereisit.hpp"
#else
#define dbg(...) 42
#endif
#define int long long
struct Person {
string name, job;
int age, pry;
Person(string _name, string _job, int _age, int _pry) {
name = _name;
job = _job;
age = _age;
pry = _pry;
}
};
class Compare {
public:
bool operator()(Person p1, Person p2){
return p1.pry < p2.pry;
}
};
int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int d, j, g;
cin >> d >> j >> g;
map<string, int> job;
for (int i = 0; i < j; i++) {
string w;
int p;
cin >> w >> p;
job[w] = p;
}
vector<int> age(126, 0);
for (int i = 0; i < g; i++) {
int l, u, p;
cin >> l >> u >> p;
for (int i = l; i <= u; i++) age[i] = p;
}
priority_queue<Person, vector<Person>, Compare> q;
while(d--) {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
string nam, w; int ag;
cin >> nam >> w >> ag;
int priority = job[w] + age[ag];
q.push(Person(nam, w, ag, priority));
}
while(!q.empty() && m != 0) {
Person v = q.top();
q.pop();
m--;
cout << v.name << " " << v.job << " " << v.age << nl;
}
}
cout << "Still unvaccinated people: " << q.size() << nl;
return 0;
}