#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0; i #define VLL vector #define VVI vector> #define VVLL vector> #define VC vector #define VS vector #define VVC vector> #define VB vector #define VVB vector> #define fore(i,a) for(auto &i:a) typedef pair P; template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1 << 29; const ll INFL = 1LL << 60; const ll mod = 1000000007; int main() { int n; cin >> n; vector> v(25); VI w(25, -1); VVB che(25, VB(25, false)); REP(_, n) { int a; cin >> a; if (a == 2) { int b; cin >> b; b--; w[b] = -1; REP(i, 25)che[b][i] = false; REP(i, 25)v[b][i] = "__"; } else if (a == 1) { string s; cin >> s; int ans = -2; REP(i, 20) { if (ans != -2)break; if (w[i] != -1) { REP(j, w[i]) { if (v[i][j] == s && che[i][j]) { che[i][j] = false; ans = i; break; } } } } cout << ans+1 << endl; } else { int aa; cin >> aa; aa--; int m; cin >> m; w[aa] = m; REP(i, m) { string s; cin >> s; v[aa].push_back(s); che[aa][i] = true; } } } }