#include<stdio.h>
#include<stdlib.>
#include<string.>
struct Node {
    int ticket;
    struct Node *next;
    struct Node *prev;
};
struct Deque {
    struct Node *front;
    struct Node *rear;
};
void initDeque(struct Deque *dq) {
    dq->front = dq->rear = NULL;
}
void joinFront(struct Deque *dq, int ticket) {
    struct Node *newNode = (structNode*)malloc(sizeof(struct Node));
    newNode->ticket = ticket;
    newNode->next = dq->front;
    newNode->prev = NULL;
    if (dq->front == NULL)
       dq->rear = newNode;
    else
       dq->front->prev = newNode;
      dq->front = newNode;
}
void joinRear(struct Deque *dq, int ticket)
{
    struct Node *newNode = (struct Node*)maaloc(sizeof(struct Node));
    newNode->ticket = ticket;
    newNode->next = NULL;
    newNode->prev = dq->rear;
    if (dq->rear == NULL)
       dq->front = newNode;
    else
       dq->rear->next = newNode;
      dq->rear = newNode;
}
void issue(struct Deque *dq) {
    if (dq->front == NULL) {
        printf("Invalid operation\n");
        return;
    }
    struct Npode *temp = dq->front;
    dq->front = dq->front->next;
    if (dq->front == NULL)
       dq->rear = NULL;
    else
       dq->front->prev = NULL;
    free(temp)''
    
}
void display(struct Deque *dq) {
    if (dq->front == NULL) {
        printf("No VIPs in queue\n");
        return;
    
}
struct Node *temp = dq->front;
while (temp != NULL) {
    printf("%d", temp->ticket);
    if (temp->next != NULL)
       printf(" ");
    temp = temp->next;
}
printf("\n");
}
int main() {
    int N;
    scanf("%d", &N);
    struct Deque dq;
    initDeque(&dq);
    char command[20];
    int x;
    for (int i = 0; i < N; i++) {
        scanf("%s", command);
        if (strcmp(command, "join_front") == 0) {
            scanf("%d", &x);
            joinFront(&dq, x);
        }
        else if (strcmp(command, "join_rear") == 0) {
            scanf("%d", &x);
            joinRear(&dq, x);
        }
        else if (strcmp(command, "issue") == 0) {
            issue(&dq);
        }
        else if (strcmp(command, "display") == 0) {
            display(&dq);
        }
        
    }
    return 0;
    
}