#include<iostream>
using namespace std;
const int N = 100010;
int  ne[N], e[N];// ne[]存储的是指针, e[]存储的是节点的值
int head;//head表示的是头节点的下标
int idx;//表示当前是第几个节点
void init()
{
    head = -1;
    idx = 0;
}
// 将x插到head后面
int add_to_head(int x)
{
    ne[idx] = head, head = idx, e[idx] = x;//ne[idx]表示第idx个节点下一个节点是插入的第几个节点,e[idx]表示第idx个节点存储的是哪一个点
    idx ++;
}
void add(int k, int x)//在k节点后面插入一个新节点
{
    ne[idx] = ne[k];
    e[idx] = x;
    ne[k] = idx ++;
    
}
void Delete(int k)//删除k节点后面的那个节点
{
    ne[k] = ne[ne[k]];
}
int main()
{  
    int t;
    cin >> t;
    init();
    while(t --)
    {
        char s;
        cin >>s;
        int i, j;
        if(s=='H')
        {
          cin >>i;
          add_to_head(i);
        }
        if(s=='D')
        {
            cin >> i;
            if(i == 0)head = ne[head];
            Delete(i);
        }
        if(s=='I')
        {
            cin >> i >> j;
            add(i, j);
        }
    }
    for(int i = head; i != -1; i = ne[i])
    {
        cout <<e[i]<<" ";
    }
}