program mn;
uses crt;
const nmax=20;
type spis=record
fam:string;
name:string;
v:integer;
end;
var a:array[1..nmax]of spis;
f:text;
s:string;n,i,j:byte;k,m,nom:integer;
BEGIN
CLrScr;
assign(f,'input.txt');
reset(f);n:=1;
While not eof(f) do
begin
with a[n] do begin
readln(f, s);
readln(f, v);
fam:=copy(s,1,pos(' ',s)-1);
delete(s,1,pos(' ',s));
name:=s;
inc(n);
end;
end;
close(f);
assign(f,'output.txt');rewrite(f);
for i:=1 to n do
if a[i].v<>0 then begin
write(f,a[i].v,':',a[i].fam,', ');
for j:=i+1 to n do
with a[j] do begin
if v=a[i].v then
begin
write(f, fam,', ');
v:=0;
end;
end;
writeln(f);
end;
close(f);
readln;
END.