N,K,Q = map(int,input().split()) from collections import deque q = deque() for _ in range(Q): t = int(input()) if t==1: s = input() q.append(s) if len(q) > N: q.popleft() else: TD = [input().split() for i in range(6)] ans = 0 rem = 60 for s,d in TD: d = int(d) time = d if s in q: time = min(d,K) if rem >= time: rem -= time ans += 1 else: break for i in range(ans): q.append(s) if len(q) > N: q.popleft() print(ans)