program editor(input,output);
var
a:array[1..2097152]of char;
n,gb,len:longint;
procedure ini;
begin
assign(input,'editor.in');assign(output,'editor.out');
reset(input);rewrite(output);
fillchar(a,sizeof(a),0);
readln(n);
gb:=1;
len:=0;
end;
procedure ins(l:longint);
var i:longint;
begin
for i:=len+l downto gb+l do a[i]:=a[i-l];
for i:=gb to gb+l-1 do read(a[i]);
len:=len+l;
readln;
end;
procedure del(l:longint);
var i:longint;
begin
for i:=gb to len-l do a[i]:=a[i+l];
len:=len-l;
end;
procedure rot(l:longint);
var i,j:longint; ch:char;
begin
i:=gb; j:=gb+l-1;
while i<j do begin
ch:=a[i];a[i]:=a[j];a[j]:=ch;
inc(i);dec(j);
end;
end;
procedure command;
var p,l,code:longint; com:char; st:string;
begin
readln(st);
p:=pos(' ',st);
com:=st[1];
delete(st,1,p);
val(st,l,code);
case com of
'I':ins(l);
'D':del(l);
'R':rot(l);
'G':writeln(a[gb]);
'M':gb:=l+1;
'P':dec(gb);
'N':inc(gb);
end;
end;
procedure main;
var i:longint;
begin
ini;
for i:=1 to n do command;
close(input);close(output);
end;
begin
main;
end.