#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define mod 1000000007
#define bug(x) cout<<"Bug "<<(x)<<endl
#define el putchar('\n')
#define sp putchar(' ')
using namespace std;
inline int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0' && ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
return;
}
const int N=1e5+10;
int n;
queue<string> q;
map<string,int> mp;
map<string,int> waiting;
map<string,int> gaming;
string last1,last2;
void leave(string t,bool f,bool force);
void add(string t,bool f);
void start()
{
if(last1!="")
{
leave(last1,0,1);add(last1,0);
gaming[last1]=0;
}
if(last2!="")
{
leave(last2,0,1);add(last2,0);
gaming[last2]=0;
}
last1="";last2="";
if(q.empty())
{
printf("Error\n");
return ;
}
int cnt=0;
while(cnt!=2)
{
string s=q.front();q.pop();
if(mp[s])
{
printf("%s ",s.c_str());
waiting[s]=0;gaming[s]=1;
if(cnt==0) last1=s;
else last2=s;
cnt++;
}
if(q.empty())
{
if(cnt==0)
{
printf("Error\n");
return ;
}
break;
}
}
el;
return ;
}
void add(string t,bool f)
{
if(mp[t])
{
if(f) printf("Error\n");
return ;
}
if(!waiting[t]) q.push(t);
mp[t]=1;waiting[t]=1;
if(f) printf("OK\n");
return ;
}
void leave(string t,bool f,bool force)
{
if((!mp[t] || gaming[t]) && !force)
{
if(f) printf("Error\n");
return ;
}
mp[t]=0;
if(f) printf("OK\n");
return ;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
string a,b;
cin>>a;
if(a[0]=='s') start();
else if(a[0]=='a')
{
cin>>b;
add(b,1);
}
else if(a[0]=='l')
{
cin>>b;
leave(b,1,0);
}
}
return 0;
}