N, K, Q = [int(i) for i in input().split()] A = [] for q in range(Q): if int(input()) == 1: A.append(input()) else: lst = [] for i in range(6): lst.append(input().split()) lst[i][1] = int(lst[i][1]) x = 0 t = 0 M = len(A) if N >= M: for i in range(6): if lst[i][0] in A: lst[i][1] = min(lst[i][1], K) else: for i in range(6): if lst[i][0] in A[M-N:]: lst[i][1] = min(lst[i][1], K) while t <= 60: t += lst[x][1] x += 1 if x == 6 and t <= 60: print(6) else: print(x-1) for i in range(6): A.append(lst[i][0])