include[HTML_REMOVED]
using namespace std;
const int N = 1E6+10;
int n;
int head,e[N],ne[N],idx;
//一开始head指向空:-1
void init(){
head = -1;
idx = 0;
}
void add_to_head(int x){
ne[idx] = head;
e[idx] = x;
head = idx ++;
}
void add(int k,int x){
ne[idx] = ne[k];
ne[k] = idx;
e[idx] = x;
idx ++;
}
void remove(int k){
ne[k] = ne[ne[k]];
}
int main(){
int k,x;
char a[2];//chat a;
//这里改成数组读入字符串可以防止读入空格//换行等杂七杂八的字符
init();
scanf("%d",&n);
while(n--){
scanf("%s",a);//scanf("%s",&a);
if(*a == 'H'){//if(a == 'H')
//*a = a[0];*(a + 1) = a[1];
scanf("%d",&x);
add_to_head(x);
}
else if(*a == 'D'){//else if(a == 'D')
scanf("%d",&k);
if(!k) head = ne[head];
else remove(k - 1);
}
else{
scanf("%d%d",&k,&x);
add(k-1,x);
}
}
for(int i = head;i != -1; i = ne[i] ){
cout << e[i] << " ";
}
cout <<endl;
}