var
f,f2:text;
s,s1,s2:string;
begin
readln(s);
assign(f,'kot.txt');
reset(f);
assign(f2,'kot2.txt');
rewrite(f2);
while not eof(f) do begin
readln(f,s2);
s1:= copy(s2,1,pos(' ',s2)-1);
if s1 = s then writeln(f2,s2);
end;
close(f);
close(f2);
end.