#include<iostream>
#include<queue>
#include<string>
using namespace std;
struct s
{
char ch[111];
int a;
int b;
int c;
bool friend operator < (s x,s y) //运算符重载(bool friend 或者friend bool operator都可以,friend代表友元函数。友元函数是指某些虽然不 是类成员却能够访问类的所有成员的函数。类授予它的友元特别的访问权。)
{
if(x.b==y.b)
return x.c>y.c;
return x.b>y.b;
}
};
int main()
{
int k=0;
priority_queue <s> pq;
s t;
string ss;
while(cin>>ss)
{
if(ss[0]=='P')
{
cin>>t.ch>>t.a>>t.b;
t.c=++k;
pq.push(t);
}
else if(ss[0]=='G')
{
if(pq.empty()) cout<<"EMPTY QUEUE!"<<endl;
else
{ t=pq.top();
cout<<t.ch<<' '<<t.a<<endl; pq.pop();
}
}
}
return 0;
}