#include <bits/stdc++.h>
// #pragma GCC optimize("O3", "Ofast", "unroll-loops")
using namespace std;
using ll = long long;
// #define int ll
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXN = 2e5 + 5;
#define cin fin
#define cout fout
ifstream cin("secv8.in");
ofstream cout("secv8.out");
mt19937 rng(time(NULL));
struct Treap
{
struct item
{
int prior, value, cnt;
bool rev;
item *l, *r;
item(int value = 0) : prior(rng()), value(value), cnt(1), rev(false), l(nullptr), r(nullptr) {}
};
using pitem = item*;
pitem root = nullptr;
int cnt(pitem it)
{
return it? it -> cnt: 0;
}
void upd_cnt(pitem& it)
{
assert(it);
it -> cnt = cnt(it -> l) + cnt(it -> r) + 1;
}
void push(pitem& it)
{
if(it && it -> rev)
{
it -> rev = false;
swap(it -> l, it -> r);
if(it -> l)
it -> l -> rev ^= 1;
if(it -> r)
it -> r -> rev ^= 1;
}
}
void merge(pitem& it, pitem l, pitem r)
{
push(l);
push(r);
if(!l || !r)
{
it = l? l: r;
return;
}
if(l -> prior > r -> prior)
{
merge(l -> r, l -> r, r);
it = l;
}
else
{
merge(r -> l, l, r -> l);
it = r;
}
upd_cnt(it);
}
void split(pitem it, pitem& l, pitem& r, int pos)
{
if(!it)
{
l = r = nullptr;
return;
}
push(it);
int szl = cnt(it -> l) + 1;
if(szl <= pos)
{
split(it -> r, it -> r, r, pos - szl);
l = it;
}
else
{
split(it -> l, l, it -> l, pos);
r = it;
}
upd_cnt(it);
}
void insert(int pos, int value)
{
pitem it1, it2;
split(root, it1, it2, pos - 1);
merge(root, it1, new item(value));
merge(root, root, it2);
}
int search(pitem it, int pos)
{
push(it);
push(it -> l);
push(it -> r);
int szl = cnt(it -> l) + 1;
if(pos == szl)
return it -> value;
else if(pos < szl)
return search(it -> l, pos);
else
return search(it -> r, pos - szl);
assert(false);
}
int access(int pos)
{
return search(root, pos);
}
void erase(int l, int r)
{
pitem it1, it2, it3;
split(root, it1, it2, l - 1);
split(it2, it2, it3, r - l + 1);
merge(root, it1, it3);
}
void reverse(int l, int r)
{
pitem it1, it2, it3;
split(root, it1, it2, l - 1);
split(it2, it2, it3, r - l + 1);
assert(it2);
it2 -> rev ^= 1;
merge(root, it1, it2);
merge(root, root, it3);
}
void output(pitem it)
{
push(it);
if(!it)
return;
output(it -> l);
cout << it -> value << ' ';
output(it -> r);
}
};
Treap treap;
int q, getout;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> q >> getout;
while(q--)
{
char ch;
cin >> ch;
int x, y;
if(ch == 'I')
{
cin >> x >> y;
treap.insert(x, y);
}
if(ch == 'A')
{
cin >> x;
cout << treap.access(x) << '\n';
}
if(ch == 'R')
{
cin >> x >> y;
treap.reverse(x, y);
}
if(ch == 'D')
{
cin >> x >> y;
treap.erase(x, y);
}
// treap.output(treap.root);
// cout << '\n';
}
treap.output(treap.root);
return 0;
}