#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int head,idx;
int e[N],ne[N];
void init()
{
head = -1;
idx = 0;
}
void add(int x)
{
e[idx] = x;
ne[idx] = head;
head = idx;
idx++;
}
void insert(int k,int x)
{
e[idx] = x;
ne[idx] = ne[k];
ne[k] = idx;
idx++;
}
void remove(int k)
{
ne[k] = ne[ne[k]];
}
int main()
{
int m;
cin >> m;
init();
while (m -- )
{
char op;
int k,x;
cin >> op;
if(op == 'H')
{
cin >> x;
add(x);
}else if(op == 'I')
{
cin >> k >> x;
insert(k-1,x);
}else
{
cin >> k;
if(!k)head = ne[head];
else remove(k-1);
}
}
for (int i = head; i != -1; i = ne[i] )cout<<e[i]<<" ";
return 0;
}