#include <bits/stdc++.h>
using namespace std;
list<string> a;
map<string, bool> m;
char c[10];
string now1 = "0", now2 = "0", t;
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; i++)
{
memset(c, 0, sizeof(c)); cin >> c;
if (c[0] == 's')
{
if (now1 != "0") a.push_back(now1);
if (now2 != "0") a.push_back(now2);
if (!a.size()) cout << "Error\n";
else if (a.size() == 1)
{
while (!m.count(a.front())) a.pop_front();
now1 = a.front(); cout << now1 << "\n";
a.pop_front(); now2 = '0';
}
else
{
while (!m.count(a.front())) a.pop_front();
now1 = a.front(); cout << a.front() << " ";
a.pop_front();
while (!m.count(a.front())) a.pop_front();
now2 = a.front(); cout << a.front() << "\n";
a.pop_front();
}
}
else if (c[0] == 'a')
{
cin >> t;
if (m.count(t)) {cout << "Error\n"; continue;}
else {m[t] = 1; a.push_back(t); cout << "OK\n";}
}
else if (c[0] == 'l')
{
cin >> t;
if (now1 == t || now2 == t || !m.count(t)) {cout << "Error\n"; continue;}
else {cout << "OK\n"; m.erase(t);}
}
}
return 0;
}