#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
    int id;
    int priority;
    struct node* next;
};
void insert(int id,int priority){
    int head;
    struct node* newnode=(struct node*)malloc(sizeof(struct node));
    newnode->id=id;
    newnode->priority=priority;
    newnode->next=NULL;
    if(head=NULL||priority>head->priority)
    {
        newnode->next=head;
        head=newnode;
    }
    else{
        struct node* temp=head;
        while(temp->next!=null&&temp->next->priority>=priority){
            temp=temp->next;
        }
        newnode->next=temp->next;
        temp->next=newnode;
    }
}
void delete(){
    if(head==NULL){
        printf("Queue is empty\n");
        return;
    }
    sruct node* temp=head;
    printf("%d\n",temp->id);
    head=head->next;
    free(temp);
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        char operation[10];
        scanf("%s",operation);
        if(strcmp(operation,"INSERT")==0){
            int id,priority;
            scanf("%d%d",&id,&priority);
            insert(id,priority);
        }
        {else if
    }
}