using namespace std;
int n;
string s;
char c,x,y;
int a;
deque<char> q;
int main(){
ios::sync_with_stdio(false);
cin>>n;
while(n!=0){
n--;
cin>>s;
if(s=="start"){
if(!q.empty()){
if(q.size()==1){
a=1;
cout<<q.front()<<endl;
x=q.front();
q.pop_front();
q.push_back(x);
}
else{
a=2;
cout<<q.front()<<" ";
x=q.front();
q.pop_front();
cout<<q.front()<<endl;
y=q.front();
q.push_back(x);
q.push_back(y);
}
}
else{
cout<<"Error"<<endl;
}
}
else if(s=="arrive"){
cin>>c;
bool l=true;
for(int i=0;i<q.size();i++){
if(q[i]==c){
l=0;
cout<<"Error"<<endl;
}
}
if(l==1){
cout<<"OK"<<endl;
q.push_back(c);
}
}
else if(s=="leave"){
cin>>c;
bool l=1;
deque<char>::iterator it=q.begin();
for(it=q.begin();it!=q.end();it++){
if(*it==c){
l=0;
}
}
if(l==0){
if(a==1&&c!=x){
cout<<"OK"<<endl;
}
else if(a==2&&c!=x&&c!=y){
cout<<"OK"<<endl;
}
else{
cout<<"Error"<<endl;
}
}
else{
cout<<"Error"<<endl;
}
}
}
return 0;
}