import sys from collections import deque, defaultdict input = sys.stdin.readline mod = 998244353 N, K, Q = map(int, input().split()) que = deque() D = defaultdict(int) for _ in range(Q): flg = int(input()) if flg == 1: S = input().rstrip('\n') que.append(S) D[S] += 1 if len(que) > N: T = que.popleft() D[T] -= 1 else: ans = 0 t_sum = 0 for _ in range(6): d, t = input().split() t = int(t) if D[d] > 0: t = min(t, K) t_sum += t if t_sum <= 60: ans += 1 print(ans)