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: Q=[list(input().split()) for _ in range(6)] for i in range(6): Q[i][1]=int(Q[i][1]) if Q[i][0] in que: Q[i][1]=min(Q[i][1],k) t,cnt=60,0 for p,d in Q: if d<=t: cnt+=1 t-=d que.append(p) que.popleft() print(cnt)