program duilie;
var
a:array[1..2000] of integer;
i,n,m,k,j,v:integer;
begin
assign(input,'queue.in');
reset(input);
assign(output,'queue.out');
rewrite(output);
readln(k);
n:=0;
m:=1;
for i:=1 to k do
begin
read(j);
case j of
1:
begin
n:=0;
m:=1;
end;
2:
begin
n:=n+1;
read(a[n]);
if n-m=10 then
begin
n:=n-1;
writeln('queue out');
end;
end;
3:
begin
m:=m+1;
if m>n+1 then
begin
m:=m-1;
writeln('queue empty');
end;
end;
4:
begin
writeln(n-m+1);
for v:=m to n do
write(a[v],' ');
end;
end;
end;
close(input);
close(output);
end.