N, K, Q = map(int, input().split()) A = [] for _ in range(Q): q = int(input()) if q == 1: A.append(input()) else: td = [tuple(input().split()) for i in range(6)] x = 0 ans = 0 l=[] for t, d in td: y = int(d) if t in A[-N:]: y = min(K, y) if x+y <= 60: ans += 1 l.append(t) x += y # print(f'{x=}') print(ans) for t in l: A.append(t)