#include<bits/stdc++.h>
using namespace std;
int n;
string p1, p2;
deque<string> q;
map<string, bool> f;
inline void solve()
{
string op, s;
cin >> op;
if (op == "start")
{
if (p1 != "")
q.push_back(p1);
if (p2 != "")
q.push_back(p2);
if (q.empty())
cout << "Error\n";
else
{
p1 = p2 = "";
if (!q.empty())
p1 = q.front(), q.pop_front();
if (!q.empty())
p2 = q.front(), q.pop_front();
cout << p1 << " " << p2 << '\n';
}
}
else if (op == "arrive")
{
cin >> s;
if (!f[s])
{
f[s] = 1, q.push_back(s);
cout << "OK\n";
}
else
cout << "Error\n";
}
else
{
cin >> s;
if (p1 != s && p2 != s && f[s])
{
f[s] = 0, q.erase(find(q.begin(), q.end(), s));
cout << "OK\n";
}
else
cout << "Error\n";
}
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
while (n--)
solve();
return 0;
}