// editor5
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *prev;
    struct node *next;
}nd;
nd *front=NULL,*rear=NULL;
void jf(int x){
    nd *newnode=(nd*)malloc(sizeof(nd));
    newnode->data=x;
    newnode->prev=NULL;
    newnode->next=NULL;
    if(front==NULL){
        front=rear=NULL;
    }else{
        front->prev=newnode;
        front=newnode;
    }
}
void jr(int x){
    nd *newnode=(nd*)malloc(sizeof(nd));
    newnode->data=x;
    newnode->next=NULL;
    newnode->prev=rear;
    if(rear==NULL){
        front=rear=newnode;
    }else
    {
        rear->next=newnode;
        rear=newnode;
    }
}
void issue(){
    if(front==NULL){
        printf("Invalid opertion\n");
        return;
    }
    nd *temp=front;
    front=front->next;
    if(front==NULL)
     rear=NULL;
    else
    front->prev=NULL;
    free(temp);
}
void display(){
    if(front==NULL){
        printf("No VIPs in queue\n");
        return;
    }
    nd *temp=front;
    while(temp!=NULL){
        printf("%d",temp->data);
        if(temp->next!=NULL)
         printf(" ");
        temp=temp->next;
    }
    printf("\n");
}
int main(){
    int x,n;
    char cmd[20];
    scanf("%d",&n);
    while(n--){
        scanf("%s",cmd);
        if(strcmp(cmd,"join_front")==0){
            scanf("%d",&x);
            jf(x);
        }else if(strcmp(cmd,"join_rear")==0){
            scanf("%d",&x);
            jr(x);
        }else if(strcmp(cmd,"issue")==0){
            issue();
        }else if(strcmp(cmd,"display")==0){
            display();
    }
    return 0;
}