#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
struct el {
int key, prior = rand(), cnt = 1;
bool rev = false;
el *l = nullptr, *r = nullptr;
el(int key) : key(key), prior(rand()) {}
};
typedef el* pi;
int cnt(pi it) {
return it ? it->cnt : 0;
}
void updcnt(pi it) {
if (it)
it->cnt = cnt(it->l) + cnt(it->r) + 1;
}
void push(pi it) {
if (it && it->rev) {
swap(it->l, it->r);
if (it->l) it->l->rev ^= 1;
if (it->r) it->r->rev ^= 1;
it->rev = false;
}
}
void split(pi t, pi &l, pi &r, int key, int add = 0) {
if (!t) {
l = r = nullptr;
return;
}
push(t);
int cur = add + cnt(t->l);
if (key <= cur) {
split(t->l, l, t->l, key, add);
r = t;
} else {
split(t->r, t->r, r, key, add + 1 + cnt(t->l));
l = t;
}
updcnt(t);
}
void merg(pi &t, pi l, pi r) {
push(l); push(r);
if (!l || !r)
t = l ? l : r;
else if (l->prior > r->prior)
merg(l->r, l->r, r), t = l;
else
merg(r->l, l, r->l), t = r;
updcnt(t);
}
void inser(pi &t, pi it, int pos) {
pi l, r;
split(t, l, r, pos);
merg(l, l, it);
merg(t, l, r);
}
void revers(pi &t, int l, int r) {
pi t1, t2, t3;
split(t, t1, t2, l);
split(t2, t2, t3, r - l + 1);
if (t2) t2->rev ^= 1;
merg(t, t1, t2);
merg(t, t, t3);
}
void delet_range(pi &t, int l, int r) {
pi t1, t2, t3;
split(t, t1, t2, l);
split(t2, t2, t3, r - l + 1);
// Ștergere din memorie
function<void(pi)> free_tree = [&](pi node) {
if (!node) return;
free_tree(node->l);
free_tree(node->r);
delete node;
};
free_tree(t2);
merg(t, t1, t3);
}
int Acces(pi &t, int pos) {
pi t1, t2, t3;
split(t, t1, t2, pos);
split(t2, t2, t3, 1);
int val = t2->key;
merg(t, t1, t2);
merg(t, t, t3);
return val;
}
void output(pi t) {
if (!t) return;
push(t);
output(t->l);
cout << t->key << " ";
output(t->r);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
srand(time(NULL));
int n, useless;
cin >> n >> useless;
pi t = nullptr;
while (n--) {
char type;
cin >> type;
if (type == 'I') {
int pos, val;
cin >> pos >> val;
--pos;
pi node = new el(val);
inser(t, node, pos);
} else if (type == 'A') {
int pos;
cin >> pos;
--pos;
cout << Acces(t, pos) << '\n';
} else if (type == 'R') {
int l, r;
cin >> l >> r;
--l; --r;
revers(t, l, r);
} else if (type == 'D') {
int l, r;
cin >> l >> r;
--l; --r;
delet_range(t, l, r);
}
}
output(t);
cout << '\n';
return 0;
}