program P935;
var
d:array[1..10000] of longint;
t1:array[1..100000] of longint;
c:array[1..10000] of string;
i,j,k,l,n,tim,y:longint;
q:string;
w:char;
begin
assign(input,'hey.in');
reset(input);
assign(output,'hey.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
read(t1[i]);
read(w); read(w);
while w<>' ' do
begin
c[i]:=c[i]+w;
read(w);
end;
readln(d[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if (t1[i]>t1[j])or((t1[i]=t1[j])and(c[i]>c[j])) then begin
y:=t1[i]; t1[i]:=t1[j]; t1[j]:=y;
q:=c[i]; c[i]:=c[j]; c[j]:=q;
y:=d[i]; d[i]:=d[j]; d[j]:=y;
end;
tim:=0;
for i:=1 to n do
if tim>t1[i] then begin writeln(c[i],' went out at time ',tim); tim:=tim+d[i] end
else begin writeln(c[i],' went out at time ',t1[i]); tim:=t1[i]+d[i]; end;
end.