var
n,q,p:integer;
s:string;
c:array[1..10]of string;
procedure fill0;
var w:integer;
begin
for w:=1 to 10 do c[w]:='';
end;
procedure input1;
begin
if p<11 then begin
c[p]:=copy(s,3,length(s)-2);
p:=p+1;
end
else begin
writeln('queue out');
end;
end;
procedure delete1;
var w:integer;
begin
if p>1 then begin
for w:=1 to p-1 do c[w]:=c[w+1];
c[p]:='';
p:=p-1;
end
else begin
writeln('queue empty');
end;
end;
procedure output1;
var w:integer;
begin
writeln(p-1);
for w:=1 to p-1 do write(c[w],' ');
write(c[p]);
end;
begin
assign(input,'queue.in');
reset(input);
assign(output,'queue.out');
rewrite(output);
readln(n);
p:=1;
for q:=1 to n do begin
readln(s);
case s[1] of
'1':fill0;
'2':input1;
'3':delete1;
'4':output1;
end;
end;
close(input);
close(output);
end.