from collections import deque n,k,q = map(int,input().split()) a = deque() for _ in range(q): if int(input())==1: a.append(input()) if len(a)>n: a.popleft() else: s = c = 0 for _ in range(6): t,d = input().split(); d = int(d) if t in a: d = min(d,k) if s+d<=60: a.append(t); c += 1 s += d while len(a)>n: a.popleft() print(c)