from collections import deque, defaultdict n, k, q = map(int, input().split()) seen_que = deque() seen_set = set() seen_dict = defaultdict(int) for _ in range(q): qq = int(input()) if qq == 1: s = input() if len(seen_que) == n: rs = seen_que.popleft() seen_dict[rs] -= 1 if seen_dict[rs] == 0: seen_set.remove(rs) seen_que.append(s) seen_dict[s] += 1 seen_set.add(s) elif qq == 2: res = 0 tt = 0 for __ in range(6): s, t = input().split() t = int(t) if s in seen_set: tt += min(t, k) else: tt += t if tt <= 60: res += 1 print(res)