n, k, Q = map(int, input().split()) lst = [] for _ in range(Q): t = int(input()) if t == 1: S = input() lst.append(S) else: ans = 0 x = 0 for i in range(6): t, d = input().split() d = int(d) if t in lst[-n:]: d = min(d, k) ans += d if ans <= 60: x += 1 print(x)