#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node {

  int key;
  struct Node *prev, *next;

};

struct Node *nil;

int insert( int key ){

  struct Node *x = (struct Node *)malloc(sizeof(struct Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

  return 0;

}

int delete( int key ){

  struct Node *cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }

  cur->prev->next = cur->next;
  cur->next->prev = cur->prev;
  free(cur);

  return 0;

}

int deleteFirst(){

  nil->next = nil->next->next;
  nil->next->next->prev = nil;
  free(nil->next);

  return 0;
  
}

int deleteLast(){

  nil->prev->prev->next = nil;
  nil->prev = nil->prev->prev;
  free(nil->prev);

  return 0;

}

int printList(){

  struct Node *cur = nil->next;
  int cnt;
  cnt = 0;

  while(1){

    if ( cur == nil ) break;
    if ( cnt++ > 0 ) printf(" ");
    printf("%d", cur->key );
    cur = cur->next;
  }

  printf("\n");

  return 0;

}

int main(){

  int i,n,key,len;
  char S[12];

  scanf("%d", &n );
  
  nil = (struct Node *)malloc(sizeof(struct Node));
  nil->next = nil;
  nil->prev = nil;
  

  for ( i = 0 ; i < n ; i++ ){

    scanf("%s", S );

    len = strlen(S);

    if ( S[0] == 'i' ) {
      scanf("%d", &key );
      insert( key );
    } else if ( len == 6 ) {
      scanf("%d", &key );
      delete( key );
    } else if ( len == 11 ) {
      deleteFirst();	
    } else {
      deleteLast();
    }

    printList();
    printf("\n");
    
  }

  printList();
  
  return 0;

}