#include <bits/stdc++.h>
using namespace std;
struct Treap {
Treap* l;
Treap* r;
int val, sz, prio;
bool rev;
};
Treap* emptyTreap = new Treap {NULL, NULL, 0, 0, 0, 0};
void unreverse(Treap* root) {
if (root != emptyTreap && root->rev) {
root->rev = 0;
root->l->rev ^= 1;
root->r->rev ^= 1;
swap(root->l, root->r);
}
}
void recompute(Treap* root) {
root->sz = root->l->sz + 1 + root->r->sz;
}
pair<Treap*, Treap*> split(Treap* root, int pos) {
if (root == emptyTreap)
return {emptyTreap, emptyTreap};
unreverse(root);
pair<Treap*, Treap*>ans;
if (root->l->sz >= pos) {
ans.second = root;
pair<Treap*, Treap*>aux = split(root->l, pos);
ans.first = aux.first;
ans.second->l = aux.second;
recompute(ans.second);
} else {
ans.first = root;
pair<Treap*, Treap*>aux = split(root->r, pos - root->l->sz - 1);
ans.second = aux.second;
ans.first->r = aux.first;
recompute(ans.first);
}
return ans;
}
Treap* join(Treap* a, Treap* b) {
unreverse(a);
unreverse(b);
if (a == emptyTreap)
return b;
if (b == emptyTreap)
return a;
if (a->prio > b->prio) {
a->r = join(a->r, b);
recompute(a);
return a;
} else {
b->l = join(a, b->l);
recompute(b);
return b;
}
}
int access(Treap* root, int pos) {
unreverse(root);
if (root->l->sz + 1 == pos)
return root->val;
if (root->l->sz >= pos)
return access(root->l, pos);
return access(root->r, pos - root->l->sz - 1);
}
Treap* ins(Treap* root, int pos, int val) {
pair<Treap*, Treap*>aux = split(root, pos - 1);
Treap* newTreap = new Treap {emptyTreap, emptyTreap, val, 1, rand(), 0};
return join(join(aux.first, newTreap), aux.second);
}
Treap* del(Treap* root, int st, int dr) {
pair<Treap*, Treap*>aux1 = split(root, st - 1);
pair<Treap*, Treap*>aux2 = split(aux1.second, dr - st + 1);
return join(aux1.first, aux2.second);
}
Treap* rev(Treap* root, int st, int dr) {
pair<Treap*, Treap*>aux1 = split(root, st - 1);
pair<Treap*, Treap*>aux2 = split(aux1.second, dr - st + 1);
aux2.first->rev ^= 1;
return join(join(aux1.first, aux2.first), aux2.second);
}
int main() {
freopen("secv8.in", "r", stdin);
freopen("secv8.out", "w", stdout);
srand(time(NULL));
int n, m;
scanf("%d%d ", &n, &m);
Treap* root = emptyTreap;
for (int i = 1; i <= n; ++i) {
char c;
scanf("%c", &c);
if (c == 'I') {
int k, e;
scanf("%d%d ", &k, &e);
root = ins(root, k, e);
} else if (c == 'A') {
int k;
scanf("%d ", &k);
printf("%d\n", access(root, k));
} else if (c == 'R') {
int st, dr;
scanf("%d%d ", &st, &dr);
root = rev(root, st, dr);
} else {
int st, dr;
scanf("%d%d ", &st, &dr);
root = del(root, st, dr);
}
}
for (int i = 1; i <= root->sz; ++i)
printf("%d ", access(root, i));
return 0;
}