#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define llong long long int main() { int n; cin >> n; vector> customers(20, map()); rep(i, n) { int command; cin >> command; int ni; string food; bool flg; switch(command) { case 0: int mi; cin >> ni >> mi; rep(i, mi) { cin >> food; if(customers[ni-1].count(food)) customers[ni-1][food] += 1; else customers[ni-1][food] = 1; } break; case 1: flg = true; cin >> food; rep(i, 20) { if(customers[i].count(food) && customers[i][food] > 0) { customers[i][food] -= 1; flg = false; cout << i+1 << "\n"; break; } } if(flg) cout << -1 << "\n"; break; case 2: cin >> ni; customers[ni-1].clear(); break; default: break; } } }