#include using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; map want[21]; for (int i = 1; i < n + 1; ++i) { int dt; cin >> dt; if (dt == 0) { int c, m; cin >> c >> m; string s; for (int i = 0; i < m; ++i) { cin >> s; ++want[c][s]; } } else if (dt == 1) { int c{ -1 }; string s; cin >> s; for (int i = 1; i < 21; ++i) { if (want[i].count(s) > 0 && want[i][s] > 0) { c = i; --want[i][s]; break; } } cout << c << "\n"; } else { int c; cin >> c; for (auto it = want[c].begin(); it != want[c].end();) it = want[c].erase(it); } } return 0; }