import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); HashMap counts = new HashMap<>(); ArrayDeque deq = new ArrayDeque<>(); while (q-- > 0) { if (sc.nextInt() == 1) { String title = sc.next(); counts.put(title, counts.getOrDefault(title, 0) + 1); deq.add(title); if (deq.size() > n) { String x = deq.poll(); if (counts.get(x) == 1) { counts.remove(x); } else { counts.put(x, counts.get(x) - 1); } } } else { String[] titles = new String[6]; int[] times = new int[6]; for (int i = 0; i < 6; i++) { titles[i] = sc.next(); times[i] = sc.nextInt(); } int count = 0; int current = 0; for (int i = 0; i < 6; i++) { int score = times[i]; if (counts.containsKey(titles[i])) { score = Math.min(score, k); } if (score + current <= 60) { current += score; count++; } else { break; } } sb.append(count).append("\n"); for (int i = 0; i < count; i++) { deq.add(titles[i]); counts.put(titles[i], counts.getOrDefault(titles[i], 0) + 1); } while (deq.size() > n) { String x = deq.poll(); if (counts.get(x) == 1) { counts.remove(x); } else { counts.put(x, counts.get(x) - 1); } } } } System.out.print(sb); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }