#include <map>
#include <list>
#include <iostream>
#include <algorithm>
#define START "start"
#define ARRIVE "arrive"
#define LEAVE "leave"
using namespace std;
list<string> QWQ;
pair<string, string> At;
map<string, bool> Mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
At.first = At.second = "";
int n;
cin >> n;
while (n--) {
string op;
cin >> op;
if (op == START) {
pair<string, string> cc = At;
if (QWQ.size() == 0) {
cout << "Error\n";
At.first = At.second = "";
}
else {
if (!(cc.first == ""))QWQ.push_back(cc.first);
if (!(cc.second == "")) QWQ.push_back(cc.second);
if (QWQ.size() > 0) {
At.first = QWQ.front();
QWQ.pop_front();
cout << At.first;
}
else At.first = "";
if (QWQ.size() > 0) {
At.second = QWQ.front();
QWQ.pop_front();
cout << " " << At.second;
}
else At.second = "";
cout << '\n';
}
}
else if (op == ARRIVE) {
string x; cin >> x;
if (Mp.count(x) || At.first == x || At.second == x) {
cout << "Error\n";
}
else {
Mp[x] = true;
QWQ.push_back(x);
cout << "OK\n";
}
}
else if (op == LEAVE) {
string x; cin >> x;
list<string>::iterator it = find(QWQ.begin(), QWQ.end(), x);
if (!Mp.count(x) || At.first == x ||
At.second == x || it == QWQ.end()) {
cout << "Error\n";
}
else {
Mp.erase(x);
QWQ.erase(it);
cout << "OK\n";
}
}
else {
cout << "404 NotFound!\n";
}
}
return 0;
}