模板
#include <bits/stdc++.h>
using i64 = long long;
int head = -1, idx = 0;
std::vector<int> v(100000), ne(100000);
void add_to_head(int x) {
v[idx] = x;
ne[idx] = head;
head = idx ++;
}
void add(int k, int x) {
v[idx] = x;
ne[idx] = ne[k];
ne[k] = idx ++;
}
void remove(int k) {
ne[k] = ne[ne[k]];
}
void solve() {
char c;
std::cin >> c;
int k, x;
if (c == 'H') {
std::cin >> x;
add_to_head(x);
} else if (c == 'D') {
std::cin >> k;
if (k == 0) {
head = ne[head];
} else {
remove(k - 1);
}
} else {
std::cin >> k >> x;
add(k - 1, x);
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t --) {
solve();
}
for (int i = head; i != -1; i = ne[i]) {
std::cout << v[i] << " ";
}
return 0;
}