var s,l,v:string;i,j,k,m,n,c:longint;a,b:array[1..10000]of longint;
begin
v:='';
readln(s);
readln(n);
readln(l);
for i:=1 to n-1 do
read(a[i]);
if n-1=0 then
readln(a[1])
else
readln(a[i+1]);
for i:=1 to length(s)-1 do
begin
m:=pos(' ',s);
for j:=1 to m-1 do
if s[j]in['0','1','2','3','4','5','6','7','8','9']then
begin
v:=v+s[j];
inc(k);
end;
val(v,b[i]);
v:='';
delete(s,1,m);
end;
if s=' ' then
c:=0
else
begin
v:=v+s;
val(v,b[k+1]);
inc(k);
end;
for i:=1 to n do
begin
if l[i]='I' then
begin
inc(k);
b[k]:=a[i];
end;
if l[i]='O' then
begin
for j:=1 to k do
if b[j]=a[i] then
begin
c:=j;
break;
end;
b[c]:=0;
dec(k);
for j:=c+1 to k+1 do
b[j-1]:=b[j];
end;
end;
if b[1]=0 then
exit;
for i:=1 to k-1 do
write(b[i],' ');
write(b[i+1]);
end.