#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
using ll = long long;
const int kMaxN = 1e5 + 10, kMaxM = 330, kInf = (((1 << 30) - 1) << 1) + 1;
int n, m, t, a[kMaxN], x;
queue<int> q1, q2[kMaxM];
string op;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++ i) {
cin >> a[i];
}
cin >> t;
for (; t; -- t) {
cin >> op;
if (op == "push") {
cin >> x;
if (!q2[a[x]].size()) {
q1.push(a[x]);
}
q2[a[x]].push(x);
} else {
cout << q2[q1.front()].front() << '\n';
q2[q1.front()].pop();
if (!q2[q1.front()].size()) {
q1.pop();
}
}
}
return 0;
}