// editor5
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct deque
{
    int data;
    struct deque *next,*prev;
}node;

node *front=NULL,*rear=NULL;

node* create(int n)
{
    node *nd=(node*)malloc(sizeof(node));
    nd->data=n;
    nd->next=nd->prev=NULL;
    return nd;
}

void insfro(int n)
{
    node *nd=create(n);
    if(front==NULL)
    {
        front=rear=nd;
    }
    else
    {
        nd->next=front;
        front->prev=nd;
        front=nd;
    }
}

void insrer(int n)
{
    node *nd=create(n);
    if(rear==NULL)
    {
        front=rear=nd;
    }
    else
    {
        nd->prev=rear;
        rear->next=nd;
        rear=nd;
    }
}

void display()
{
    if(front==NULL)
    {
        printf("\nNO VIP's in queue");
        return;
    }
    node *temp=front;
    printf("\n");
    while(temp!=NULL)
    {
        printf("%d ",temp->data);
        temp=temp->next;
    }
}

void issue()
{
    if(rear==NULL)
    {
        printf("Invalid operation\n");
        return;
    }
    if(front==rear)
    {
        front=rear=NULL;
    }
    else
    {
        node *temp=front;
        front=front->next;
        front->prev=NULL
        temp->next=NULL;
        free(temp);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        char ops[20];
        int data;
        scanf("%s",ops);
        if(!strcmp("join_front",ops))
        {
            scanf("%d",&data);
            insfro(data);
        }
        if(!strcmp("join_rear",ops))
        {
            scanf("%d",&data);
            insrer(data);
        }
        if(!strcmp("display",ops))
        {
            display();
        }
        if(!strcmp("issue",ops))
        {
            issue();
        }
    }
}