#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
    int data;
    struct node *prev;
    struct node *next;
}Node;
Node *front=NULL,*rear=NULL;
void join_front(int x){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=x;
    newnode->prev=NULL;
    newnode->next=front;
    if(front==NULL){
        front=rear=newnode;
    }
    else{
        front->prev=newnode;
        front=newnode;
    }
}
void join_rear(int x){
    Node *newnode=(Node*)malloc(sizeof(Node));
    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 operation\n");
        return;
    }
    Node *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;
    }
    Node *temp=front;
    while(temp!=NULL){
        printf("%d",temp->data);
        if(temp->next!=NULL)
            printf("");
        temp=temp->next;
    }
    printf("\n");
}
int main(){
    int n,x;
    char cmd[20];
    scanf("%d",&n);
    while(n--){
        scanf("%s",cmd);
        if(strcmp(cmd,"join_front")==0){
            scanf("%d",&x);
            join_front(x);
        }
        else if(strcmp(cmd,"join_rear")==0){
            scanf("%d",&x);
            join_rear(x);
        }
         else if(strcmp(cmd,"issue")==0){
            issue();
        }
         else if(strcmp(cmd,"display")==0){
            display();
        }
    }
    return 0;
}