#include<iostream>
#include<queue>
#include<map>
using namespace std;
int n;
string op;
char c;
deque<char>q;
char had1=' ', had2=' ';
map<char, bool>m;
bool start;
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n;
while(n--){
cin>>op;
if(op=="start"){
start=1;
if(had1!=' ') q.push_back(had1), had1=' ';
if(had2!=' ') q.push_back(had2), had2=' ';
if(q.empty()) cout<<"Error\n";
else{
if(q.size()==1) cout<<q.front()<<"\n", had1=q.front(), q.pop_back();
else{
if(had1>had2) swap(had1, had2);
cout<<q.front()<<" ", had1=q.front(), q.pop_front(), cout<<q.front()<<"\n", had1=q.front(), q.pop_front();
}
}
}
else if(op=="arrive"){
cin>>c;
if(m.count(c)) cout<<"Error\n";
else q.push_back(c), m[c]=1, cout<<"OK\n";
}
else{
cin>>c;
if(!m.count(c) || had1==c || had2==c) cout<<"Error\n";
else{
m.erase(c);
for(int i=0; i<(int)q.size(); i++){
q.erase(q.begin()+i);
}
cout<<"OK\n";
}
}
}
}
20分