N,K,Q = map(int,input().split()) A = set() for i in range(Q): q = int(input()) if q == 1: s = input() A.add(s) else: ans = 0 T = 0 f = 1 for i in range(6): t,dd = map(str,input().split()) d = int(dd) if t in A: d = min(d,K) if T + d > 60: f = 0 if f: T += d ans += 1 A.add(t) print(ans)