var
q:array [1..2000] of integer;
tmp,n,code,t,i,j,head,tail:integer;
begin
fillchar (q,sizeof(q),0);
head:=1;tail:=0;
assign (input,'queue.in');
reset (input);
readln (n);
assign (output,'queue.out');
rewrite (output);
for i:=1 to n do begin
read (tmp);
case tmp of
1:tail:=head-1;
2:if tail-head=9 then writeln ('queue out') else begin
read (t);
inc(tail);
q[tail]:=t;
end;
3:if tail=head-1 then writeln ('queue empty') else inc(head);
4:begin
code:=tail-head+1;
write (code);
writeln;
write (q[head]);
for j:=head+1 to tail do write (' ',q[j]);
end;
end;
readln;
end;
close (output);
close (input);
end.