import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n,k,q = map(int,input().split()) a = deque() d = defaultdict(int) for i in range(q): t = int(input()) if t == 1: s = input().rstrip() a.append(s) d[s] += 1 while len(a) > n: d[a.popleft()] -= 1 else: now = 0 cnt = 0 sol = [] for i in range(6): l = list(input().split()) t = int(l[1]) if d[l[0]] >= 1: t = min(t, k) if now + t <= 60: now += t cnt += 1 sol.append(l[0]) for pro in sol: a.append(pro) d[pro] += 1 while len(a) > n: d[a.popleft()] -= 1 print(cnt)