const max=1000;
type queue=record
data:array[0..max-1] of integer;
front,rear:integer;
end;
var Q:queue;
n,i,j,k,a,b:integer;
procedure iniqueue(var Q:queue);
begin
Q.front:=-1;
Q.rear:=-1;
end;
function qempty(Q:queue):boolean;
begin
qempty:=(Q.front=Q.rear);
end;
function qfull(Q:queue):boolean;
begin
if Q.front=-1 then
qfull:=(Q.rear-Q.front=10)
else qfull:=(Q.rear-Q.front=10-1);
end;
procedure inqueue(var Q:queue; x:integer);
begin
if qfull(Q) then writeln('queue out')
else begin
Q.rear:=Q.rear+1;
Q.data[Q.rear]:=x;
inc(k);
end;
end;
procedure delqueue(var Q:queue; var x:integer);
begin
if qempty(Q) then writeln('queue empty')
else begin
Q.front:=Q.front+1;
x:=Q.data[Q.front];
dec(k);
end;
end;
{function gethead(Q:queue):integer;
begin
if qempty(Q) then halt
else gethead:=Q.data[Q.front+1];
end; }
begin
assign(input,'queue.in');
assign(output,'queue.out');
reset(input);
rewrite(output);
readln(n);
iniqueue(Q); k:=0;
for i:=1 to n do
begin
read(a);
if a=1 then iniqueue(Q);
if a=2 then begin readln(b);inqueue(Q,b); end;
if a=3 then delqueue(Q,b);
if a=4 then begin writeln(k); for j:=Q.front+1 to Q.rear do write(Q.data[j],' ') end;
end;
close(input);
close(output);
end.