/*
ID: chsc4691
PROG: gift1
LANG: C++
*/
#include <fstream>
using namespace std;
ifstream cin("gift1.in");
ofstream cout("gift1.out");
int n;
struct
fri
{
string name;
int
money, given, recei;
fri()
{
name = "";
money = given = recei = 0;
}
void
give(int out, int i, fri *fa)
{
if(money >= out)
{
this -> money -= out;
this -> given += out;
fa[i].money += out;
fa[i].recei += out;
}
}
}friends[11];
int
__locate__(string name)
{
for(int i = 1; i <= n; i++)
if(friends[i].name == name)
return i;
return 0;
}
void
__read__()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> friends[i].name;
for(int i = 1; i <= n; i++)
{
string frin;
int
mny, num, outn;
cin >> frin >> mny >> num;
int j = __locate__(frin);
friends[j].money = mny;
if(num != 0)
{
outn = mny / num;
for(int k = 1; k <= num; k++)
{
string tn;
cin >> tn;
friends[j].give(outn, __locate__(tn), friends);
}
}
}
}
void
__print__()
{
for(int i = 1; i <= n; i++)
cout << friends[i].name << " " << friends[i].recei - friends[i].given << endl;
}
int
main()
{
__read__();
__print__();
return 0;
}