#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,t=0;
string s="",ss="",a,o;
queue<string>q;
multiset<string>d;
map<string,int>mp;
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>o;
if(o=="start"){
if(t>=1)q.push(s);
if(t>=2)q.push(ss);
while(!q.empty()){
if(d.find(q.front())==d.end())q.pop();
else if(mp[q.front()]>=2)mp[q.front()]--,q.pop();
else break;
}
if(q.empty()){
cout<<"Error\n";
t=0;
}
else {
t=1;
s=q.front();
cout<<q.front()<<" ";
q.pop();
while(!q.empty()){
if(d.find(q.front())==d.end())q.pop();
else if(mp[q.front()]>=2)mp[q.front()]--,q.pop();
else break;
}
if(!q.empty()){
t++;
ss=q.front();
cout<<q.front();
q.pop();
}
cout<<"\n";
}
}
if(o=="arrive"){
cin>>a;
if(d.find(a)!=d.end()){
cout<<"Error\n";
continue;
}
d.insert(a);
q.push(a);
cout<<"OK\n";
mp[a]++;
}
if(o=="leave"){
cin>>a;
if((t>=1&&s==a)||(ss==a&&t==2)||d.find(a)==d.end()){
cout<<"Error\n";
continue;
}
cout<<"OK\n";
d.erase(d.find(a));
}
}
}