const
fail='Ignored';
type
web=array[1..100] of string[70];
var
a,b:web;
s:string[70];
i,j,x:integer;
begin
readln(s);
while s<>'QUIT' do
begin
i:=i+1;
{ERROR}
if (s[1]='V') and (s[2]='I') and (s[3]='S') and (s[4]='I') and (s[5]='T') then
begin
x:=x+1;
j:=j+1;
a[j]:=copy(s,7,length(s));
b[i]:=a[j];
end else
if s='BACK' then if x<>1 then
begin
x:=x-1;
b[i]:=a[x];
end else b[i]:=fail
else if s='FORWARD' then if x<i then
begin
x:=x+1;
b[i]:=a[x];
end else b[i]:=fail;
readln(s);
end;
for j:=1 to i do writeln(b[j]);
end.
program pro40(input,output);
const
fail='Ignored';
type
web=array[1..100] of string[70];
var
a,b:web;
s:string[70];
i,j,x:integer;
begin
readln(s);
while s<>'QUIT' do
begin
i:=i+1;
if (s[1]='V') and (s[2]='I') and (s[3]='S') and (s[4]='I') and (s[5]='T') then
begin
x:=x+1;
j:=j+1;
a[j]:=copy(s,7,length(s));
b[i]:=a[j];
end else
if s='BACK' then if x<>1 then
begin
x:=x-1;
b[i]:=a[x];
end else b[i]:=fail
else if s='FORWARD' then if x<i then
begin
x:=x+1;
b[i]:=a[x];
end else b[i]:=fail;
readln(s);
end;
for j:=1 to i do writeln(b[j]);
end.