from collections import defaultdict N, K, Q = map(int, input().split()) memory = defaultdict(int) mcnt = 0 hist = [] i_hist = 0 for _ in range(Q): a = int(input()) if a == 1: s = input() memory[s] += 1 mcnt += 1 hist.append(s) if N < len(memory): memory[hist[i_hist]] -= 1 mcnt -= 1 i_hist += 1 else: time = 0 cnt = 0 tmp = [] for _ in range(6): t, d = input().split() d = int(d) if t in memory and 0 < memory[t]: time += min(K, d) else: time += d if time <= 60: cnt += 1 tmp.append(t) for t in tmp: memory[t] += 1 mcnt += 1 hist.append(t) if N < len(memory): memory[hist[i_hist]] -= 1 mcnt -= 1 i_hist += 1 print(cnt)