#include <bits/stdc++.h>
using namespace std;
namespace Treap {
struct Node {
Node *l = 0, *r = 0;
int x = 0;
int y = 0;
int sz = 0;
int rev = 0;
Node(int _x = 0) : x(_x), y(rand()), rev(1), sz(1) {}
void recalc();
};
int cnt(Node *t) {
if(!t) return 0;
return t -> sz;
}
void Node::recalc() {
sz = cnt(l) + cnt(r) + 1;
if(rev) {
rev = 0;
swap(l, r);
if(l) l->rev ^= 1;
if(r) r->rev ^= 1;
}
}
pair< Node*, Node* > split(Node *t, int k) {
if(!t) return {};
t->recalc();
if(cnt(t->l) >= k) {
auto pa = split(t->l, k);
t->l = pa.second;
t->recalc();
return {pa.first, t};
} else {
auto pa = split(t->r, k - cnt(t->l) - 1);
t->r = pa.first;
t->recalc();
return {t, pa.second};
}
return {};
}
Node* join(Node* l, Node* r) {
if(!l) return r;
if(!r) return l;
l->recalc();
r->recalc();
if(l->y > r->y) {
l->r = join(l->r, r);
l->recalc();
return l;
} else {
r->l = join(l, r->l);
r->recalc();
return r;
}
}
int access(Node *t, int k) {
if(!t) return -1;
t->recalc();
if(cnt(t->l) + 1 == k) return t -> x;
if(cnt(t->l) >= k) return access(t->l, k);
return access(t->r, k-cnt(t->l)-1);
}
Node* insert(Node *t, int e, int k) {
auto pa = split(t, k-1);
return join(pa.first, join(new Node(e), pa.second));
}
Node* reverse(Node *t, int i, int j) {
auto pa = split(t, i-1);
auto u = split(pa.second, j-i+1);
u.first->rev ^= 1;
return join(pa.first, join(u.first, u.second));
}
Node* erase(Node *t, int i, int j) {
auto pa = split(t, i-1);
auto u = split(pa.second, j-i+1);
return join(pa.first, u.second);
}
void output(Node *t, ostream &os) {
if(!t) return;
t->recalc();
output(t->l, os);
os << t->x << ' ';
output(t->r, os);
return;
}
}
int main() {
#ifdef BLAT
freopen("input", "r", stdin);
#else
freopen("secv8.in", "r", stdin);
freopen("secv8.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(time(nullptr));
Treap::Node *root = 0;
int n, pl;
cin >> n >> pl;
for(int i = 0; i < n; ++i) {
char c;
cin >> c;
if(c == 'I') {
int e, k;
cin >> k >> e;
root = Treap::insert(root, e, k);
}
if(c == 'A') {
int k;
cin >> k;
cout << Treap::access(root, k) << '\n';
}
if(c == 'R') {
int i, j;
cin >> i >> j;
root = Treap::reverse(root, i, j);
}
if(c == 'D') {
int i, j;
cin >> i >> j;
root = Treap::erase(root, i, j);
}
}
Treap::output(root, cout);
return 0;
}