#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <sstream>
using namespace std;
const int N = 100010, M = 2 * N;
int e[N], ne[N], idx, head;
void init() {
idx = 0;
head = -1;
memset(ne, -1, sizeof ne);
}
void add_to_head(int a) {
e[idx] = a;
ne[idx] = head;
head = idx++;
}
void add(int a, int b) {
e[idx] = b;
ne[idx] = ne[a];
ne[a] = idx++;
}
void removeIt(int a) {
ne[a] = ne[ne[a]];
}
int main()
{
init();
int m;
scanf("%d", &m);
string line;
int k, x;
char op;
getline(cin, line);
while(m--) {
getline(cin, line);
stringstream scin(line);
scin >> op;
if (op == 'H') {
scin >> x;
add_to_head(x);
} else if (op == 'D') {
scin >> k;
if (k == 0) {
head = ne[head];
continue;
}
removeIt(k - 1);
} else {
scin >> k >> x;
add(k - 1, x);
}
}
for (int i = head; ~i; i = ne[i]) {
printf("%d ", e[i]);
}
}