#include<bits/stdc++.h>
using namespace std;
queue<string>q,yw;
map<string,bool>pd,pdw;
string name,zl,w[5]={"1","1","1"};
int n,c=2;
int main ( )
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n;
while(n--)
{
cin>>zl;
if(zl=="start")
{
while(!yw.empty())
{
q.push(yw.front());
pdw[yw.front()]=0;
yw.pop();
}
c=2;
while(c>0&&!q.empty())
{
while(q.size()>0&&pd[q.front()]==0)q.pop();
if(q.empty()||pd[q.front()]==0)break;
yw.push(q.front());
w[c]=q.front();
pdw[q.front()]=1;
q.pop();
c--;
}
if(c==2)cout<<"Error\n";
else
{
for(int i=2;i>c;i--)cout<<w[i]<<" ";
cout<<"\n";
}
}
else if(zl=="arrive")
{
cin>>name;
if(pd[name]==1||pdw[name]==1)cout<<"Error\n";
else
{
pd[name]=1;
cout<<"OK\n";
q.push(name);
}
}
else if(zl=="leave")
{
cin>>name;
if(pd[name]==0||pdw[name]==1)cout<<"Error\n";
else
{
pd[name]=0;
pdw[name]=0;
cout<<"OK\n";
}
}
}
}