import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int q = sc.nextInt(); List list = new ArrayList<>(); PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { int tp = sc.nextInt(); if (tp == 1) { list.add(sc.next()); } else { int[] t = new int[6]; String[] d = new String[6]; for (int j = 0; j < 6; j++) { d[j] = sc.next(); t[j] = sc.nextInt(); } int sum = 0; int m = list.size(); int ans = 6; for (int j = 0; j < 6; j++) { boolean flg = false; for (int j2 = Math.max(m - n, 0); j2 < m; j2++) { if (list.get(j2).equals(d[j])) { flg = true; break; } } if (flg) { sum += Math.min(t[j], k); } else { sum += t[j]; } if (sum > 60) { ans = j; break; } } pw.println(ans); } } pw.flush(); sc.close(); } }