from collections import deque N,K,Q = map(int,input().split()) A = deque([]) for i in range(Q): q = int(input()) if q == 1: s = input() if s not in A: A.append(s) if len(A) > N: A.popleft() else: ans = 0 T = 0 f = 1 for i in range(6): t,dd = map(str,input().split()) d = int(dd) X = [] if t in A: d = min(d,K) if T + d > 60: f = 0 if f: T += d ans += 1 for x in X: A.append(x) if len(A) > N: A.popleft() print(ans)