n,k,q=map(int,input().split()) stack=[] for _ in range(q): q1=int(input()) if q1==1: s=input() stack.append(s) else: Q=[list(input().split()) for _ in range(6)] for i in range(6): Q[i][1]=int(Q[i][1]) for j in range(min(n,len(stack))): if stack[-1-j]==Q[i][0]: Q[i][1]=min(Q[i][1],k) Q.sort(key=lambda x:x[1]) t,cnt=60,0 for p,c in Q: if c<=t: cnt+=1 t-=c print(cnt)