#include<iostream>
#include<cstdlib>
#include<cstring>
#include<fstream>
using namespace std;
short n;
int main()
{
ifstream fin("gift1.in");
fin>>n;
string name[10];
short fn[10];
short given[10];
short gotten[10]={0};//这个必须初始化
short i;
for (i=0; i<n; fin>>name[i++]);
short j,k;
string t;
short x;
for (i=0; i<n; i++)
{
fin>>t;
for (x=0; x<n; x++)
if (t==name[x])
break;
//根据姓名搜索匹配 x即为送礼者的编号
fin>>given[x];
fin>>fn[x];
for (j=0; j<fn[x]; j++)
{
fin>>t;
for (k=0; k<n; k++)
if (t==name[k])
break;
//根据姓名搜索匹配 k为收礼者编号
gotten[k]+=(given[x]/fn[x]);
}
}
fin.close();
ofstream fout("gift1.out");
for (i=0; i<n; i++)
{
if (fn[i]==0) //防止被0除
fout<<name[i]<<" "<<(gotten[i]+given[i])<<endl;
else
fout<<name[i]<<" "<<(given[i]%fn[i]+gotten[i]-given[i])<<endl;
//注意送礼余下的钱算进收益
}
fout.close();
return 0;
}