N,K,Q = map(int,input().split()) dict = {} cnt = 1 def check(x): if x in dict: if dict[x] > cnt-N-1: return True else: return False else: return False def addd(x): global cnt for xx in x: dict[xx] = cnt cnt+=1 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 asa = [] 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 asa.append(nex2[0]) else: flg = False else: ti = int(nex2[1]) if tes + ti <= 60: tes += ti ans = j+1 asa.append(nex2[0]) else: flg = False addd(asa) print(ans) #ans #print(dict,cnt)