from collections import deque N, K, Q = map(int,input().split()) q = deque([]) while Q: Q -= 1 n = int(input()) #print(q) if n == 1: a = input() q.appendleft(a) if len(q) > N: q.pop() else: P = [] now = 0 ans = 0 for i in range(6): t, d = input().split() d = int(d) if t in q: if now + min(d, K) <= 60: now += min(d, K) ans += 1 else: if now + d <= 60: now += d ans += 1 P.append(t) print(ans) for i in range(6): q.appendleft(P[i]) if len(q) > N: q.pop()