1 #pragma GCC optimize("Ofast")
2 #include <bits/stdc++.h>
3 #define maxn 13003
4 #define _for(i,a,b) for(int i = (a);i < b;i ++)
5 typedef long long ll;
6 using namespace std;
7
8 inline ll read()
9 {
10 ll ans = 0;
11 char ch = getchar(), last = ' ';
12 while(!isdigit(ch)) last = ch, ch = getchar();
13 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
14 if(last == '-') ans = -ans;
15 return ans;
16 }
17 inline void write(ll x)
18 {
19 if(x < 0) x = -x, putchar('-');
20 if(x >= 10) write(x / 10);
21 putchar(x % 10 + '0');
22 }
23 int NP;
24 map<string,int> m;
25 vector<string> v;
26 int main()
27 {
28 NP = read();
29 _for(i,0,NP)
30 {
31 string t;
32 cin >> t;
33 v.push_back(t);
34 m[t] = 0;
35 }
36
37 _for(i,0,NP)
38 {
39 string t;
40 cin >> t;
41 auto iter = m.find(t);
42 int a,b;
43 cin >> a >> b;
44 if(b)
45 iter->second -= b*(a/b);
46 _for(i,0,b)
47 {
48 string t2;
49 cin >> t2;
50 m[t2] += a/b;
51 }
52 }
53
54 _for(i,0,NP)
55 {
56 auto iter = m.find(v[i]);
57 cout << iter->first << " " << iter->second << endl;
58 }
59 return 0;
60 }