N,K,Q = map(int, input().split()) A = [] for t in range(Q): qu = int(input()) if qu == 1: A.append(input()) # print(A[max(0,len(A)-N):]) else: B = [] for i in range(6): B.append(list(input().split())) time = 0 res = 0 for n, t in B: t = int(t) if n in A[max(0,len(A)-N):]: time += min(t, K) else: time += t if time <= 60: res += 1 print(res) for n,t in B: A.append(n)