var
n,i,j,k,l:longint;
f:string;
q:char;
s:string;
c:array [0..10000] of string;
t,d:array[0..10000] of longint;
begin
assign(input,'hey.in');
reset(input);
assign(output,'hey.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
read(t[i]);
read(q);read(q);
s:='';
while q<>' ' do
begin
s:=s+q;
c[i]:=s;
read(q);
end;
read(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;
close (input);
close(output);
end.