#include <bits/stdc++.h>
using namespace std;
#define SC scanf
#define PF printf
#define ull unsigned long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sort_a(a) sort(a.begin(),a.end());
#define sort_d(a) sort(a.rbegin(),a.rend());
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define rev(s) reverse(s.begin(),s.end())
#define P(ok) cout << (ok ? "YES\n": "NO\n")
#define __Heart__ ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll> PII;
struct heart {
int priority , position , age ;
string name , job ;
};
bool compare(const heart& a, const heart& b) {
if (a.priority != b.priority) return a.priority < b.priority;
return a.position > b.position;
}
void solve()
{
priority_queue<heart, vector<heart>, decltype(&compare)> pq(compare);
int d , j , g , job_priority , age , l , u , p , n , m ,availableVacine = 0 , rnk = 0 ; cin >> d >> j >> g ;
string name , job ;
map < string , int > jobRank ;
map < int , int > ageRank ;
for(int i = 0 ; i < j ; i++){
cin >> job >> job_priority ;
jobRank[job] = job_priority ;
}
for(int i = 0 ; i < g ; i++) {
cin >> l >> u >> p ;
for(int j = l ; j <= u ; j++) ageRank[j] = p ;
}
while(d--){
cin >> n >> m ;
availableVacine += m ;
for(int i = 0 ; i < n ; i++){
cin >> name >> job >> age ;
int priorityOfthisPerson = ageRank[age] + jobRank[job] ;
pq.push({priorityOfthisPerson , rnk++ , age , name , job}) ;
}
}
while(availableVacine-- && !pq.empty()){
auto it = pq.top() ;
pq.pop() ;
cout << it.name << " " << it.job << " " << it.age << "\n" ;
}
cout << "Still unvaccinated people: " << pq.size() << "\n" ;
}
int main()
{
__Heart__
// READ("9.in") ;
// WRITE("0out.txt") ;
int t ; t = 1; while(t--) solve() ;
}