program ex(f1,f2);
const
yichu='queue out';
queshao='queue empty';
type
zn=array [0..3000] of longint;
var
a:zn; f1,f2:text; head,tail:integer; i,j,k,n,m,p:integer;
begin
assign(f1,'queue.in'); reset(f1);
assign(f2,'queue.out'); rewrite(f2);
readln(f1,n);
head:=1; tail:=0;
for i:=1 to n do
begin
read(f1,j);
if j=2 then read(f1,k);
readln(f1);
case j of
1: begin
head:=1; tail:=0;
end;
2: if (tail-head)>8 then writeln(f2,yichu)
else begin
inc(tail);
a[tail]:=k;
end;
3: if head>tail then writeln(f2,queshao)
else inc(head);
4: begin
writeln(f2,tail-head+1);
for p:=head to tail-1 do write(f2,a[p],' ');
writeln(f2,a[tail]);
end;
end;
end;
close(f1);
close(f2);
end.