var
n,i,j,k,l:integer;
f:string;
c:array[0..10000]of string;
t,d:array[0..10000] of integer;
begin
readln(n);
for i:=1 to n do
begin
readln(t[i]); readln(c[i]); readln(d[i]);
end;
for i:=1 to n do
for j:=i+1 to n do
begin
if t[i]=t[j] then
if c[i][1]>c[j][1]
then
begin
k:=t[i]; t[i]:=t[j]; t[j]:=k;
f:=c[i]; c[i]:=c[j]; c[j]:=f;
k:=d[i]; d[i]:=d[j]; d[j]:=k;
end;
if t[i]>t[j] then begin
k:=t[i]; t[i]:=t[j]; t[j]:=k;
f:=c[i]; c[i]:=c[j]; c[j]:=f;
k:=d[i]; d[i]:=d[j]; d[j]:=k;
end;
end;
write(c[1],' ','went out at time',' ',t[1]);
writeln;
for i:=2 to n do
begin
if d[i-1]+t[i-1]>t[i] then
t[i]:=d[i-1]+t[i-1];
write(c[i],' ','went out at time',' ',t[i]);
writeln;
end;
end.