#include using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector v[20]; vector used[20]; for (int i = 0; i < n; i++) { int d; cin >> d; if (d == 0) { int n, m; cin >> n >> m; n--; v[n].resize(m); used[n].assign(m, false); for (int j = 0; j < m; j++) { cin >> v[n][j]; } } else if (d == 1) { string b; cin >> b; int ans = -1; for (int j = 0; j < 20; j++) { for (int k = 0; k < (int)v[j].size(); k++) { if (used[j][k]) continue; if (v[j][k] == b) { used[j][k] = true; ans = j + 1; break; } } if (ans != -1) break; } cout << ans << endl; } else if (d == 2) { int c; cin >> c; c--; v[c].clear(); used[c].clear(); } } return 0; }