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