#include <cstdio>
#include <iostream>
 
using namespace std;
 
const int N = 100010;
 
int head, M, ne[N], e[N], idex;
 
void init() {
  head = -1;
  idex = 0;
}
 
void add_to_head(int x) {
  ne[idex] = head;
  head = idex;
  e[idex] = x;
  idex++;
}
 
void add(int k, int x) {
  ne[idex] = ne[k];
  ne[k] = idex;
  e[idex] = x;
  idex++;
}
 
void remove(int k) { ne[k] = ne[ne[k]]; }
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  init();
  cin >> M;
  while (M--) {
    char op;
    int k, x;
    cin >> op;
    if (op == 'H') {
      cin >> x;
      add_to_head(x);
    } else if (op == 'I') {
      cin >> k >> x;
      add(k - 1, x);
    } else {
      cin >> k;
      if (k == 0) {
        head = ne[head];
      } else {
        remove(k - 1);
      }
    }
  }
  int cur = head;
  while (cur != -1) {
    cout << e[cur] << " ";
    cur = ne[cur];
  }
  return 0;
}