/*
ID: emergen1
LANG: C++
PROG: gift1
*/
#include<fstream>
#include<string>
#include<map>
using namespace std;
int main()
{
ofstream fout("gift1.out");
ifstream fin("gift1.in");
int groupNum;
fin>> groupNum;
map <string, int> people;
string keys[groupNum];
string person;
for (int i (0) ; i <groupNum ; i++)//now i have all the people
{
fin>>person;
keys[i] = person;
people[person] = 0;
}
string name;
int num, faces;
while ( 1 )
{
fin>>name >>num >>faces;//reads in, who, what hisoriginal amount, and howmany people to split it with
if(num == 0 && faces == 0)
break;
people[name] -= (num - (num % faces));
for (int i(0) ; i < faces ; i++)//gives gifts to other friends
{
fin>>name;
people[name] += (num / faces);
}
}
for (int i(0) ; i < groupNum ; i++)
fout<<keys[i] <<" " <<people[keys[i]] <<endl;
return 0;
}