N,K,Q=map(int,input().split()) A=[] for tests in range(Q): x=int(input()) if x==1: s=input() A.append(s) else: X=[] now=0 U=[input().split() for i in range(6)] for tests in range(6): x,y=U[tests] y=int(y) if x in A[max(0,len(A)-N):]: now+=min(K,y) else: now+=y if now<=60: X.append(x) else: print(tests) break else: print(6) A+=X