#include<bits/stdc++.h>
using namespace std;
queue<string>s;
int n,c=0;
string a,x,y,l,r;
bool fh(){
int c=0;
string f;
for(int i=1;i<=s.size();i++){
f=s.front();
s.pop();
s.push(f);
if(f==x){
c=1;
}
}
if(c){
return true;
}
else{
return false;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a;
l="0";
r="0";
if(a=="start"){
if(l!="0"){
s.push(l);
s.pop();
if(r!="0"){
s.push(r);
s.pop();
}
}
if(!s.empty()&&s.size()>=2){
l=s.front();
for(int i=1;i<=s.size();i++){
if(i==2){
r=s.front();
}
s.push(s.front());
s.pop();
}
cout<<l<<" "<<r<<"\n";
}
else if(!s.empty()&&s.size()>=1){
l=s.front();
cout<<l<<"\n";
}
else{
cout<<"Error\n";
}
}
if(a=="arrive"){
cin>>x;
if(x==l||x==r||fh()){
cout<<"Error\n";
}
else{
s.push(x);
cout<<"OK\n";
}
}
if(a=="leave"){
cin>>x;
if(x==l||x==r||s.empty()){
cout<<"Error\n";
}
else{
cout<<"OK\n";
s.pop();
}
}
}
return 0;
}