#include<iostream>
#include<string>
#include<string.h>
#include<queue>
using namespace std;
struct node
{
char str[100];
int cc, num, id;//num编号,id优先级
friend bool operator < ( node x, node y)
{
if(x.id == y.id)
return x.num > y.num;
else
return x.id > y.id;
}
};
int main()
{
node now;
char c[4];
int temp = 0;
priority_queue<node>q;
while(scanf("%s", c) != EOF)
{
if(!strcmp(c, "GET"))
{
if(q.empty())
printf("EMPTY QUEUE!\n");
else
{
now = q.top();
q.pop();
printf("%s %d\n", now.str, now.cc);
}
}
else
{
scanf("%s%d%d", now.str, &now.cc, &now.id);
now.num = ++temp;
q.push(now);
}
}
return 0;
}