#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e5 + 5;
string que[N];
map<string,int> mp;
map<string,int> pl;
int len=0;
queue<string> q;
int head,till;
int main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
while(n--){
string sj;
cin >> sj;
string x;
if(sj == "start"){
if(!len){
cout << "Error\n";
}else{
while(!q.empty()){
que[++till] = q.front();
pl[q.front()] = 0 ;
mp[q.front()] = till;
len++;
q.pop();
}
int res=0;
int l2=len;
for(int i = head;i <= till && res < min(l2,2);i++){
if(que[i].size() &&!( que[i] == " ")){
q.push(que[i]);
cout<<que[i]<<" ";
pl[que[i]] = 1;
head = i + 1;
len--;
res++;
}
}
cout<<"\n";
}
}else if(sj=="arrive"){
cin >> x;
if(mp[x]||pl[x]){
cout<<"Error\n";
}else{
cout<<"OK\n";
que[++till] = x;
len++;
mp[x] = till;
}
}else{
cin >> x;
if(mp.find(x) == mp.end()|| pl[x]){
cout << "Error\n";
}else{
cout<<"OK\n";
que[mp[x]] = " ";
len--;
mp.erase(x);
}
}
}
return 0;
}