N,K,Q = map(int,input().split()) dict = {} cnt = 1 def check(x): global cnt if x in dict: if dict[x] > cnt-N-1: return True else: return False else: return False for i in range(Q): que = int(input()) if que == 1: nex = input() dict[nex] = cnt cnt += 1 else: tes = 0 ans = 0 flg = True for j in range(6): nex2 = list(map(str,input().split())) if not flg: continue # print("j",j,"tes",tes) if check(nex2[0]): ti = min(int(nex2[1]),K) if tes + ti <= 60: tes += ti ans = j+1 else: flg = False else: ti = int(nex2[1]) if tes + ti <= 60: tes += ti ans = j+1 else: flg = False print(ans) #ans #print(dict,cnt)