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