import sys N, K, Q = map(int, input().split()) se = set() query = sys.stdin.read().splitlines() i = 0 lq = len(query) while i < lq: line = query[i] if line == "1": i += 1 se.add(query[i]) elif line == "2": ans = 0 time = 0 tmp_se = set() for j in range(6): i += 1 t, d = query[i].split() tmp_se.add(t) d = int(d) if t in se: d = min(d, K) time += d if time <= 60: ans += 1 print(ans) se = tmp_se i += 1