#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct Node{
    int data;
    struct Node* next;
} Node;

Node* createNode(int value){
    Node* newNode = (Node*)malloc(sizeof(Node));
    newNode -> data = value;
    newNode -> next = NULL;
    return newNode;
}

// Node ** head: Truyền vào địa chỉ của con trỏ
void insertAtBack(Node** head, int value){
    Node* newNode = createNode(value);
    
    // Nếu linked list ban đầu là rỗng, thì thêm trực tiếp
    if(*head == NULL){
        *head = newNode;
        return;
    }
    
    // Duyệt đến node cuối của Linked lis
    Node* current = *head;
    while(current -> next != NULL){ 
        current = current -> next;
    }
    
    current -> next = newNode;
    return;
    
}

// **head: Địa chỉ của con trỏ head
void insertAtK(Node** head, int value, int k){
    Node* newNode = createNode(value);
    
    // Nếu k = 0, quay về thao tác thêm đầu
    if(k == 0){
        // Nếu danh sách liên kết hiện tại là rỗng
        if(*head == NULL){
            *head = newNode;
            return;
        }
        else{
            newNode -> next = *head;
            *head = newNode;
            return;
        }
    }
    
    Node* current = *head;
    int countNode = 0;
    while(current -> next != NULL && countNode < k - 1){
        current = current -> next;
        countNode++;
    }
    
    // Nếu node hiện tại là node cuối (quay về thao tác thêm cuối)
    if(current -> next == NULL){
        current -> next = newNode;
    }
    else{ // Nếu node hiện tại là node giữa (thực hiện 2 lần gán)
        newNode -> next = current -> next;
        current -> next = newNode;
    }
    
}

void printList(Node* head){
    Node* current = head;
    if(current == NULL){
        printf("EMPTY\n");
        return;
    }
    
    while(current != NULL){
        printf("%d ", current -> data);
        current = current -> next;
    }
    printf("\n");
}

int main() {
    int q;
    scanf("%d",&q);
    
    // Linked list
    Node* head = NULL;
    
    for(int i=1;i<=q;i++){
        char command[30];
        scanf("%s", command);
        if(strcmp(command, "INSERT") == 0){
            int k, value;
            scanf("%d %d",&k ,&value);
            insertAtK(&head, value, k);
        }
        else if(strcmp(command, "PUSH_BACK") == 0){
            int value;
            scanf("%d",&value);
            insertAtBack(&head, value);
        }
        else if(strcmp(command, "PRINT") == 0){
            printList(head);
        }
    }
    return 0;
}
