#include <bits/stdc++.h>
using namespace std;
struct nod{
int val, prior, sz, flip;
nod *st, *dr; } *nil = new nod { 0, 0, 0, 0, nullptr, nullptr };
using ns = nod*;
void delete_tree(ns n){
if(n == nil) return;
delete_tree(n->st);
delete_tree(n->dr);
delete n; }
ns prop(ns n){
if(n != nil && n->flip){
n->flip = 0;
n->st->flip ^= 1, n->dr->flip ^= 1;
swap(n->st, n->dr); }
return n; }
ns mod_fiu(ns n, const int care, ns fiu){
(care ? n->dr : n->st) = fiu;
n->sz = 1 + n->st->sz + n->dr->sz;
return n; }
ns join(ns st, ns dr){
prop(st), prop(dr);
return st == nil ? dr :
dr == nil ? st :
(st->prior > dr->prior) ? mod_fiu(st, 1, join(st->dr, dr)) :
mod_fiu(dr, 0, join(st, dr->st)); }
struct pns { ns l, r; };
pns split(ns n, const int where){
while(n->sz < where);
prop(n);
pns t = {};
const int lsz = n->st->sz;
return where == 0 ? pns{nil, n} :
where == n->sz ? pns{n, nil} :
(where <= lsz) ? (t = split(n->st, where ), t.r = mod_fiu(n, 0, t.r), t) :
(t = split(n->dr, where-lsz-1), t.l = mod_fiu(n, 1, t.l), t); }
void print(ns n, ofstream& g){
if(n == nil) return;
prop(n);
print(n->st, g);
g << n->val << ' ';
print(n->dr, g); }
int main(){
srand(time(nullptr));
ifstream f("secv8.in");
ofstream g("secv8.out");
int n, useless;
f >> n >> useless;
ns rad = nil;
while(n--){
char ch;
int a, b;
f >> ws >> ch >> a;
if(ch != 'A') f >> b;
if(ch == 'I'){
pns t = split(rad, a-1);
rad = join(join(t.l, new nod { b, rand(), 1, 0, nil, nil }), t.r); }
else if(ch == 'R'){
pns p = split(rad, a-1), q = split(p.r, b-a+1);
q.l->flip ^= 1;
rad = join(join(p.l, q.l), q.r); }
else if(ch == 'D'){
pns p = split(rad, a-1), q = split(p.r, b-a+1);
delete_tree(q.l);
rad = join(p.l, q.r); }
else{
pns p = split(rad, a-1), q = split(p.r, 1);
g << q.l->val << '\n';
rad = join(join(p.l, q.l), q.r); } }
print(rad, g);
return 0; }