#include<iostream>
#include<queue>
#include<string>
using namespace std;
typedef struct node
{
string ss;
int par;
int pri;
int num;
friend bool operator < (node a,node b)
{
if(a.pri != b.pri)
return a.pri > b.pri;
else
return a.num >b.num;
}
}Node;
int main()
{
string str;
priority_queue<Node> Q;
int k=1;
while(cin>>str)
{
Node p,q;
if(str == "GET")
{
if(!Q.empty())
{
q = Q.top();
Q.pop();
cout<<q.ss<<" "<<q.par<<endl;
}
else
{
cout<<"EMPTY QUEUE!"<<endl;
}
}
if(str == "PUT")
{
string str1;
int a,b;
cin>>str1>>a>>b;
p.ss = str1;
p.par = a;
p.pri = b;
p.num = k;
Q.push(p);
k++;
}
}
return 0;
}