#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
    int data;
    struct node *next;
}

struct node *front == NULL;
struct node *rear == NULL;

void join_rear(int x){
    struct  node *n = malloc(sizeof(struct node));
    n->data= x;
    n->next = NULL;
    if(rear == NULL)
        front = rear = n;
    else{
        rear->next = n;
        rear = n;
    }
}

void issue(){
    if(front == NULL){
    printf("Invalid operation\n");
    return ;
}
struct node *t = front;
front = front->next;
  if(front == NULL)
  rear = NULl;
 free(t);
 }
 void display(){
     if(front == NULL){
         printf("No VIPs in queue\n");
         return ;
     }
     struct node *t = front;
     while(t != NULL){
         printf("%d ", t->data);
         t = t->next;
     }
     printf("\n");
 }
 
 int main(){
     int n, x;
     char cmd[20];
     
     scanf("%d", &n);
     
     for(int i = 0; i < n; i++){
         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(x);
         }
         else if(strcmp(cmd, "display")== 0){
             display();
         }
     }
     return 0;
 }