from collections import deque N, K, Q = map(int, input().split()) A = deque() for _ in range(Q): t = int(input()) if t == 1: A.append(input()) else: tot = ans = 0 TD = [list(input().split()) for _ in range(6)] for t, d in TD: u = int(d) if t in A: u = min(u, K) if 60 < tot + u: break A.append(t) tot += u ans += 1 print(ans) while N < len(A): A.popleft()