#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long MOD = 1000000007; vector< vector > V(21); int func( string s ) { for ( int i = 1; i <= 20; i++ ) { for ( int j = 0; j < V[i].size(); j++ ) { if ( V[i][j] == s ) { V[i].erase( V[i].begin()+j ); return i; } } } return -1; } int main() { int N; cin >> N; vector ans; for ( int i = 0; i < N; i++ ) { int a; cin >> a; if ( a == 0 ) { int n,m; cin >> n >> m; for ( int j = 0; j < m; j++ ) { string s; cin >> s; V[n].push_back(s); } } else if ( a == 1 ) { string s; cin >> s; ans.push_back( func(s) ); } else { int c; cin >> c; V[c].clear(); } } for ( int i = 0; i < ans.size(); i++ ) { cout << ans[i] << endl; } return 0; }