var name:array[1..10] of string;
givename:array[1..10] of string;
save,osave:array[1..10]of integer;
i,j,k,l,a,b,n:integer;
fin,fout:text;
c:integer;
begin
assign(fin,'gift1.in');reset(fin);
readln(fin,n);
for i:=1 to n do
readln(fin,name);
for i:=1 to n do
begin
c:=0;
readln(fin);
readln(fin,a,b);
osave:=osave+a;
if b>0 then
begin
c:=a div b;
save[n]:=save[n]-a;
for k:=1 to b do
readln(fin,givename[k]);
for j:=1 to b do
for l:=1 to n do
begin
if name[l]=givename[j] then
save[l]:=c+save[l];
end;
end
else save:=save+a;
end;
close(fin);
assign(fout,'gift1.out');
rewrite(fout);
for i:=1 to n do
writeln(fout,name,'_',save-osave);
close(fout);
end.