program ex;
type
ss=array[1..100]of integer;
var
f:ss;
n:integer;
x,y:integer;
head,tail,i,j:integer;
begin
assign(input,'queue.in');
assign(output,'queue.out');
reset(input);
rewrite(output);
readln(n);
head:=1;tail:=0;
for i:=1 to n do
begin
read(x);
case x of
1: begin
head:=1;
tail:=0;
end;
2: begin
readln(y);
if tail-head+1=10 then writeln('queue out')
else begin
inc(tail);
f[tail]:=y;
end;
end;
3: begin
if head>tail then writeln('queue empty')
else inc(head);
end;
4: if head<=tail then
begin
writeln(tail-head+1);
for j:=head to tail-1 do write(f[j],' ');
writeln(f[tail]);
end;
end;
end;
close(input);
close(output);
end.