import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static String[] sushi = new String[53]; static int index = 0; static int[][] s = new int[21][53]; public static void main(String[] args) { int n = sc.nextInt(); all:for(int i = 0; i < n; i++) { int type = sc.nextInt(); if(type == 0) { int id = sc.nextInt(); int m = sc.nextInt(); for(int j = 0; j < m; j++) { int sid = sushi2id(sc.next()); s[id][sid]++; } } if(type == 1) { String name = sc.next(); int b = sushi2id(name); for(int j = 1; j < s.length; j++) { if(s[j][b] != 0) { s[j][b]--; System.out.println(j); continue all; } } System.out.println("-1"); } if(type == 2) { int id = sc.nextInt(); s[id] = new int[53]; } } } static int sushi2id(String str) { for(int i = 0; i < index; i++) { if(sushi[i].equals(str)) return i; } sushi[index] = str; index++; return index - 1; } }