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