def solve(N, K, Q): A = [] for _ in range(Q): query = int(input()) if query == 2: time = 0 correct = 0 B = [] for i in range(6): t, d = input().split() d = int(d) seen = False for j in range(N): if 0 <= len(A)-1-j: if A[-1-j] == t: seen = True break else: break if seen: time += min(K, d) else: time += d if time <= 60: correct += 1 B.append(t) A.extend(B) print(correct) else: A.append(input()) N, K, Q = map(int, input().split()) solve(N, K, Q)