#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct Treap;
typedef Treap* Arbore;
typedef pair<Arbore, Arbore> Paa;
Arbore NIL;
struct Treap {
int val, prio, g, rev;
Treap *st, *dr;
Treap(int val) : val(val), prio(rand()), g(1), rev(0), st(NIL), dr(NIL) {}
void recalc() {
g = st->g + dr->g + 1;
}
void prop() {
if (rev) {
swap(st, dr);
st->rev ^= 1;
dr->rev ^= 1;
rev = 0;
}
}
};
Arbore join(Arbore a, Arbore b) {
if (a == NIL) return b;
if (b == NIL) return a;
a->prop();
b->prop();
if (a->prio > b->prio) {
a->dr = join(a->dr, b);
a->recalc();
return a;
} else {
b->st = join(a, b->st);
b->recalc();
return b;
}
}
/// Split dupa nodul cu pozitia 'pos',
/// pozitiile indexate de la 1
/// bucata din stanga va avea pos noduri
Paa split(Arbore x, int pos) {
if (x == NIL) return {NIL, NIL};
x->prop();
if (pos <= x->st->g) {
Paa s = split(x->st, pos);
x->st = s.second;
x->recalc();
return {s.first, x};
} else {
Paa s = split(x->dr, pos - x->st->g - 1);
x->dr = s.first;
x->recalc();
return {x, s.second};
}
}
int get_el(Arbore x, int pos) {
x->prop();
if (pos <= x->st->g)
return get_el(x->st, pos);
if (pos == x->st->g + 1)
return x->val;
return get_el(x->dr, pos - x->st->g - 1);
}
void print(Arbore root) {
printf("%d: ", root->g);
for (int i = 1; i <= root->g; ++i)
printf("%d-", get_el(root, i));
printf("\n");
}
int main() {
NIL = new Treap(-1);
NIL->g = 0;
NIL->prio = -1;
NIL->st = NIL->dr = NIL;
freopen("secv8.in", "r", stdin);
freopen("secv8.out", "w", stdout);
int n, k;
scanf("%d%d ", &n, &k);
Arbore root = NIL;
for (int i = 1; i <= n; i++) {
char c;
scanf("%c", &c);
if (c == 'I') {
int k, e;
scanf("%d%d ", &k, &e);
Paa s = split(root, k - 1);
root = join(s.first, join(new Treap(e), s.second));
} else if (c == 'A') {
int k;
scanf("%d ", &k);
printf("%d\n", get_el(root, k));
} else if (c == 'R') {
int l, r;
scanf("%d%d ", &l, &r);
Paa s1 = split(root, l - 1);
Paa s2 = split(s1.second, r - l + 1);
s2.first->rev ^= 1;
root = join(s1.first, join(s2.first, s2.second));
} else {
int l, r;
scanf("%d%d ", &l, &r);
Paa s1 = split(root, l - 1);
Paa s2 = split(s1.second, r - l + 1);
root = join(s1.first, s2.second);
}
}
print(root);
return 0;
}