#include <bits/stdc++.h>
using namespace std;
int m;
int l[100005], r[100005], data[100005], hd, tl, tmp;
int main () {
cin >> m;
for (int i = 1; i <= m; i++) {
string s;
int x, y;
cin >> s;
if (s == "L") {
tmp++;
cin >> x;
data[tmp] = x;
r[tmp] = hd;
l[hd] = tmp;
hd = tmp;
}
else if (s == "R" ) {
tmp++;
cin >> x;
data[tmp] = x;
l[tmp] = tl;
r[tl] = tmp;
tl = tmp;
}
else if (s == "D") {
cin >> x;
int x1 = l[x], x2 = r[x];
r[x1] = x2;
l[x2] = x1;
}
else if (s == "IL") {
cin >> x >> y;
tmp++;
int x1 = l[x];
data[tmp] = y;
l[y] = x1;
r[y] = x;
r[x1] = tmp;
l[x] = tmp;
if (x == hd) {
hd = tmp;
}
}
else{
tmp++;
cin >> x >> y;
int x1 = r[x];
data[tmp] = y;
r[x] = tmp;
r[tmp] = x1;
l[x1] = tmp;
l[tmp] = x;
if (x == tl) {
tl = tmp;
}
}
}
int tmp = hd;
while (1) {
if (tmp == 0) break;
printf("%d ", data[tmp]);
tmp = r[tmp];
}
return 0;
}