var a:array [1..10] of string;
b:array [1..10] of longint;
np,ng,i,j,k,l,money:longint;
s:string;
begin
assign(input,'gift1.in');
assign(output,'gift1.out');
reset(input);
rewrite(output);
readln(np);
for i:=1 to np do
readln(a[i]);
for i:=1 to np do
begin
readln(s);
readln(money,ng);
if ng<>0 then for j:=1 to np do
if a[j]=s then begin
b[j]:=b[j]+money mod ng;
b[j]:=b[j]-money;
break;
end;
if ng<>0 then for j:=1 to ng do
begin
readln(s);
for k:=1 to np do
if a[k]=s then
b[k]:=b[k]+money div ng;
end;
end;
for i:=1 to np do
writeln(a[i],' ',b[i]);
close(input);
close(output);
end.