import java.util.ArrayList; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); Map> map = new TreeMap>(); StringBuilder sb = new StringBuilder(); for(int i = 0; i < N; i++) { int t = scan.nextInt(); if(t == 0) { int n = scan.nextInt(); int m = scan.nextInt(); ArrayList list = new ArrayList(); for(int j = 0; j < m; j++) { String s = scan.next(); list.add(s); } map.put(n, list); }else if(t == 1) { String s = scan.next(); boolean flag = false; for(int j : map.keySet()) { ArrayList list = map.get(j); for(int k = 0; k < list.size(); k++) { if(s.equals(list.get(k))) { list.remove(k); map.put(j, list); sb.append(j).append("\n"); flag = true; break; } } if(flag) { break; } } if(!flag) { sb.append(-1).append("\n"); } }else { int n = scan.nextInt(); map.remove(n); } } scan.close(); System.out.println(sb.toString()); } static void disp(ArrayList list) { for(String s : list) { System.out.print(s + " "); } System.out.println(); } }