#include <bits/stdc++.h>
using namespace std;
struct Node {
Node* l;
Node* r;
int val, sz, prio;
bool rev;
};
Node* en=new Node{NULL,NULL,0,0,0,0};
void rec(Node* root){
if (root!=en){
root->sz=root->l->sz+1+root->r->sz;
}
}
void unrev(Node* root){
if (root!=en&&root->rev){
swap(root->l,root->r);
root->l->rev^=1;
root->r->rev^=1;
root->rev=0;
}
}
pair<Node*, Node*>split(Node* root, int pos){
if (root==en)
return {en,en};
unrev( root);
pair<Node*, Node*>ans, aux;
if(pos<=root->l->sz){
ans.second=root;
aux=split(root->l, pos);
ans.first=aux.first;
ans.second->l=aux.second;
rec(ans.second);
}else{
ans.first=root;
aux=split(root->r, pos-root->l->sz-1);
ans.second=aux.second;
ans.first->r=aux.first;
rec(ans.first);
}
return ans;
}
Node* join(Node*a, Node*b){
unrev(a);
unrev(b);
if (a==en)
return b;
if (b==en)
return a;
if(a->prio>b->prio){
a->r=join(a->r, b);
rec(a);
return a;
}else{
b->l=join(a, b->l);
rec(b);
return b;
}
}
Node* ins(Node* root, int pos, int val){
Node* nn=new Node{en, en, val, 1, rand(), 0};
pair<Node*, Node*>aux=split(root, pos-1);
return join(join(aux.first, nn), aux.second);
}
Node* del(Node* root, int l, int r){
pair<Node*, Node*>aux1=split(root, l-1);
pair<Node*, Node*>aux2=split(aux1.second, r-l+1);
return join(aux1.first, aux2.second);
}
Node* rev(Node* root, int l, int r){
pair<Node*, Node*>aux1=split(root, l-1);
pair<Node*, Node*>aux2=split(aux1.second, r-l+1);
aux2.first->rev^=1;
return join(join(aux1.first, aux2.first), aux2.second);
}
int access(Node*root, int pos){
unrev(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);
}
int main() {
srand(time(NULL));
freopen("secv8.in", "r", stdin);
freopen("secv8.out", "w", stdout);
int n, k;
scanf("%d%d ", &n, &k);
Node* root = en;
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;
}