#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
    int data;
    struct Node*prev;
    struct Node*next;
};

struct Node* createNode(int data)
{
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    if(newNode == NULL)
    {
        printf("Memory allocation failed\n");
        exit(1);
    }
    newNode->data = data;
    newNode->prev = NULL;
    newNode->next = NULL;
    return newNode;
}

void join_front(struct Node** front, struct Node** rear,int data)
{
    struct Node* newNode = createNode(data);
    if(*front == NULL)
    {
        *front = *rear = newNode;
    }
    else
    {
        newNode->next = *front;
        (*front)->prev = newNode;
        *front = newNode;
    }
}
void join_rear(struct Node** front, struct Node** rear,int data)
{
    struct Node* newNode = createNode(data);
    if(*rear == NULL)
    {
        *front = *rear = newNode;
    }
    else
    {
        newNode->next = *rear;
        (*rear)->next = newNode;
        *rear = newNode;
    }
}
void issue(struct Node** front, struct Node** rear,int data)
{
    if(*front == NULL)
    {
        printf("Invalid operation\n");
    }
    struct Node* temp = *front;
    *front = (*front)->next;
    if(*front == NULL)
    {
        *rear = NULL;
    }
    else
    {
        (*front)->prev=NULL;
    }
    free(temp);
}
void display(struct Node* front)
{
    if(front == NULL)
    {
        printf("No VIPs in queue");
    }
    struct Node* current = front;
    while(current != NULL)
    {
        printf("%d",current->data);
        if(current->next !=NULL)
        {
            printf("-");
        }
        current = current->next;
    }
    printf("\n");
}

int main()
{
    struct Node* front = NULL;
    struct Node* rear = NULL;
    int N;
    scanf("%d",&N);
    char command[20];
    int ticket_number;
    
    for(int i=0;i<N;i++)
    {
        if(strcmp(command,"join_front")==0)
        {
            scanf("%d",&ticket_number);
            join_front(&front,&rear,ticket_number);
        }
        else if(strcmp(command,"join_rear")==0)
        {
            scanf("%d",&ticket_number);
            join_front(&front,&rear,ticket_number);
        }
        else if(strcmp(command,"issue")==0)
        {
            issue(&front,&rear);
        }
        else if(strcmp(command,"display")==0)
        {
            display(front);
        }
    }
    while(front!=NULL)
    {
        struct Node* temp = front;
        front = front->next;
        free(temp);
    }
return 0;
}