#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define down(i, l, r) for(int i = l; i >= r; i--)
#define MS 2345678
#define MAX 1037471823
#define Q 1
using namespace std;
int m, a, b, n, s[MS], h[MS], l[MS], r[MS], next[MS], last, now;
bool rev[MS];
char c[MS], q[10];
int New() { int o = last; last = next[o]; s[o] = 1, h[o] = l[o] = r[o] = c[o] = rev[o] = 0; return o; }
void Cal(int o) { if (!o) return; s[o] = s[l[o]]+s[r[o]]+1; }
void Down(int o) { if (!o) return; int x; if (rev[o]) x = l[o], l[o] = r[o], r[o] = x, rev[o] ^= 1, rev[l[o]] ^= 1, rev[r[o]] ^= 1; }
void Splay(int x)
{
if (!x) return; int o = h[x]; Down(x);
while (o)
{
if (l[o] == x) { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o]; l[o] = r[x]; h[r[x]] = o; h[o] = x; r[x] = o; Cal(o); }
else { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o]; r[o] = l[x]; h[l[x]] = o; h[o] = x; l[x] = o; Cal(o); }
o = h[x];
}
Cal(x);
}
int FindRW(int rr)
{
int o = l[0]; Down(o);
while (rr != s[l[o]])
{
if (rr < s[l[o]]) o = l[o]; else rr -= s[l[o]]+1, o = r[o];
Down(o);
}
return o;
}
void InsertP(int o, int n)
{
int ln = (n-1) / 2, rn = n - ln - 1;
if (ln) { int now = New(); h[now] = o, l[o] = now; InsertP(now, ln); }
c[o] = 0; while (c[o] < 32 || 126 < c[o]) scanf("%c", &c[o]);
if (rn) { int now = New(); h[now] = o, r[o] = now; InsertP(now, rn); }
Cal(o);
}
void Insert(int b, int n) { Splay(FindRW(b)); Splay(FindRW(b+1)); int o = New(); h[o] = l[l[0]]; r[l[l[0]]] = o; InsertP(o, n); Cal(l[l[0]]); Cal(l[0]); }
void DeleteP(int o) { if (l[o]) DeleteP(l[o]); if (r[o]) DeleteP(r[o]); next[o] = last, last = o; }
void Delete(int b, int n) { Splay(FindRW(b-1)); Splay(FindRW(b+n)); DeleteP(r[l[l[0]]]); r[l[l[0]]] = 0; Cal(l[l[0]]); Cal(l[0]); }
void Rev(int b, int n) { Splay(FindRW(b-1)); Splay(FindRW(b+n)); int o = r[l[l[0]]]; rev[o] ^= 1; Splay(o); }
int main()
{
s[1] = 2, s[2] = 1; l[0] = 1, l[1] = 2, h[2] = 1; rep(i, 3, MS-1) next[i] = i+1; last = 3; now = 0;
scanf("%d", &m);
rep(i, 1, m)
{
scanf("%s", q);
if (q[0] == 'M') scanf("%d", &now);
else if (q[0] == 'I') { scanf("%d", &n); Insert(now, n); }
else if (q[0] == 'D') { scanf("%d", &n); Delete(now+1, n); }
else if (q[0] == 'R') { scanf("%d", &n); Rev(now+1, n); }
else if (q[0] == 'G') printf("%c\n", c[FindRW(now+1)]);
else if (q[0] == 'P') now--; else now++;
}
return 0;
}
I2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxxdWV1ZT4KCiNkZWZpbmUgcmVwKGksIGwsIHIpIGZvcihpbnQgaSA9IGw7IGkgPD0gcjsgaSsrKQojZGVmaW5lIGRvd24oaSwgbCwgcikgZm9yKGludCBpID0gbDsgaSA+PSByOyBpLS0pCiNkZWZpbmUgTVMgMjM0NTY3OAojZGVmaW5lIE1BWCAxMDM3NDcxODIzCiNkZWZpbmUgUSAxCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG0sIGEsIGIsIG4sIHNbTVNdLCBoW01TXSwgbFtNU10sIHJbTVNdLCBuZXh0W01TXSwgbGFzdCwgbm93Owpib29sIHJldltNU107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