#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
deque<pair<string,bool> > dq;
void change(){
while(dq.size()&&dq.front().second==0) dq.pop_front();
if(!dq.size()) return ;
dq.push_back(dq.front());
dq.pop_front();
}
signed main(){
int n,qwq=0;
string s,x;
cin>>n;
while(n--){
cin>>s;
if(s=="start"){
while(dq.size()&&dq.front().second==0) dq.pop_front();
if(dq.size()) for(int i=1;i<=qwq;++i) change();
while(dq.size()&&dq.front().second==0) dq.pop_front();
if(dq.empty()) cout<<"Error"<<endl;
else if(dq.size()==1){
cout<<dq.front().first<<endl;
qwq=1;
}
else{
auto fir=dq.front();
cout<<dq.front().first<<' ';
dq.pop_front();
while(dq.size()&&dq.front().second==0) dq.pop_front();
if(dq.size()){
cout<<dq.front().first<<endl;
qwq=2;
}
else{
cout<<endl;
qwq=1;
}
dq.push_front(fir);
}
}
else if(s=="arrive"){
cin>>x;
bool f=0;
for(auto i:dq){
if(i.first==x&&i.second){
f=1;
cout<<"Error"<<endl;
break;
}
}
if(f!=1) continue;
dq.push_back({x,1});
cout<<"OK"<<endl;
}
else{
cin>>x;
while(dq.size()&&dq.front().second==0) dq.pop_front();
deque<pair<string,bool> >::iterator it=find(dq.begin(),dq.end(),make_pair(x,1));
if(dq.empty()||it==dq.end()) cout<<"Error"<<endl;
else if(qwq>=1&&dq.front().first==x) cout<<"Error"<<endl;
else if(qwq==2){
auto fir=dq.front();
dq.pop_front();
while(dq.size()&&dq.front().second==0) dq.pop_front();
if(dq.front().first==x) cout<<"Error"<<endl;
else{
for(auto i:dq){
if(i.first==x) i.second=0;
}
cout<<"OK"<<endl;
}
dq.push_front(fir);
}
else{
for(auto i:dq){
if(i.first==x) i.second=0;
}
cout<<"OK"<<endl;
}
}
}
return 0;
}