from collections import deque n,k,q=map(int,input().split()) que=deque([0]*n) for _ in range(q): q1=int(input()) if q1==1: s=input() que.append(s) que.popleft() else: sum_d,ans=0,0 solved=[] for _ in range(6): t,d=input().split() d=int(d) if t in que: d=min(d,k) if sum_d+d<=60: sum_d+=d ans+=1 solved.append(t) for t in solved: que.append(t) que.popleft() print(ans)