#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#include int main() { int n; cin >> n; bool f[22] = {}; map>r; while (n--) { int x; cin >> x; if (!x) { int a, b; cin >> a >> b; f[a] = 1; for (int i = 0; i < b; i++) { string p; cin >> p; r[a].push_back(p); } //cout << a << endl;; } if (x == 1) { string p; cin >> p; bool z = 1; for (int i = 1; i <= 20; i++) { //cout << f[i]; if (f[i]) { // cout << i; for (int j = 0; j < r[i].size(); j++) { if (r[i][j] == p) { cout << i << endl; r[i][j] = "0"; z = 0; break; } } } if (!z)break; } if (z)cout << -1 << endl; } if (x == 2) { int a; cin >> a; f[a] = 0; // cout << a << endl; } } return 0; }