#include <bits/stdc++.h>
#define int long long
#define MAXN 1000010
using namespace std;
int T,last,l,r,len;
string opt;
map<string,int> a,b;
string Q[MAXN],x;
void solve()
{
cin>>T;
while(T--)
{
cin>>opt;
if(opt=="start")
{
while(last)
{
last--;
while(!a[Q[l]]) l++;
Q[r++]=Q[l];
b[Q[l]]=0;
l++;
}
if(len==1)
{
last=1;
while(!a[Q[l]]) l++;
cout<<Q[l]<<'\n';
b[Q[l]]=1;
}
else if(len>=2)
{
last=2;
while(!a[Q[l]]) l++;
cout<<Q[l]<<' ';
b[Q[l]]=1;
int tmp=l+1;
while(!a[Q[tmp]]) tmp++;
cout<<Q[tmp]<<'\n';
b[Q[tmp]]=1;
}
else cout<<"Error"<<'\n';
}
else if(opt=="arrive")
{
cin>>x;
if(a[x])
cout<<"Error"<<'\n';
else
{
Q[r++]=x;
a[x]=1;
len++;
cout<<"OK"<<'\n';
}
}
else
{
cin>>x;
if(b[x]||!a[x])
cout<<"Error"<<'\n';
else
{
a[x]=0;
len--;
cout<<"OK"<<'\n';
}
}
}
}
signed main()
{
ios::sync_with_stdio(0);
int _T=1;
while(_T--) solve();
return 0;
}