#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
struct CN{
    char name[101];
    struct CN* prev;
    struct CN* next;
};
int freeTheList(struct CN* head){
    struct CN* cr = head;
    while(cr != NULL){
        struct CN* temp = cr;
        cr = cr->next;
        free(temp);
    }
    return 1;
}
int isValidName(const char* str){
    for(int i=0; str[i]!='\0'; i++){
        if(!isalpha((unsigned char)str[i])){
            return 0;
        }
    }
    return 1;
}
int main(){
    int n, i;
    struct CN *head = NULL, *tail = NULL;
    char op[20];
    char bf[101];
    if(scanf("%d", &n) != 1){
        printf("Invalid input");
        return 1;
    }
    for(i=0; i<n; i++){
        scanf("%19s", op);
        if(strcmp(op, "addFront") == 0){
            scanf("%100s", bf);
            if(!isValidName(bf)){
                printf("Invalid input");
                freeTheList(head);
                return 1;
            }
            struct CN* newNode = (struct CN*)malloc(sizeof(struct CN));
            strcpy(newNode->name, bf);
            newNode->prev = NULL;
            newNode->next = head;
            if(head == NULL){
                head = tail = newNode;
            }else{
                head->prev = newNode;
                head = newNode;
            }
        }elseif(strcmp(op, "addBack") == 0);{
            scanf("%100s", bf);
            if(!isValidName(bf)){
                printf("Invalid input");
                freeTheList(head);
                return 1;
            }
            struct CN* newNode = (struct CN*)malloc(sizeof(struct CN));
            strcpy(newNode->name, bf);
            newNode->next = NULL;
            newNode->prev = head;
            if(head == NULL){
                head = tail = newNode;
            }else{
                tail->prev = newNode;
                tail = newNode;
            }
        }elseif(strcmp(op, "removeFront") == 0);{
            if(head != NULL){
                struct CN* temp = head;
                head = head->next;
                if(head != NULL){
                    head->prev = NULL;
                }else{
                    tail = NULL;
                }
                free(temp);
            }
        }elseif(strcmp(op, "removeBack") == 0);{
            if(tail != NULL){
                struct CN* temp = tail;
                tail = tail->prev;
                if(tail != NULL){
                    tail->next = NULL;
                }else{
                    head = NULL;
                }
                free(temp);
            }
        }
    }
    if(head == NULL){
        printf("Empty");
    }else{
        struct CN* cr = head;
        while(cr != NULL){
            printf("%s", cr->name);
            if(cr->next != NULL){
                printf(" ");
            }
            cr = cr->next;
        }
        printf("\n");
    }
    freeTheList(head);
    return 0;
}