#include<iostream>
using namespace std;
const int N = 100010;
int e[N], en[N], p,head=-1;
void headinsert(int x)
{
e[p] = x, en[p] = head, head = p++;
}
void insert(int k,int x)
{
e[p] = x, en[p] = en[k], en[k] = p++;
}
void del(int k)
{
en[k] = en[en[k]];
}
int main()
{
char a;
int n,k,x;
cin >> n ;
while (n--)
{
cin >> a ;
if (a == 'D')
{
cin >> k;
if (!k)head = en[head];
else del(k-1);
}
else if (a == 'I')
{
cin >> k;
cin >> x;
insert(k-1, x);
}
else
{
cin >> x;
headinsert(x);
}
}
for (int i = head; i != -1; i = en[i])
{
cout << e[i]<<" ";
}
return 0;
}