I,R,P=input,range,print def J(): return map(int,I().split()) N,K,Q=J() A=[] for q in R(Q): t=I() if t=="1":A+=[I()] else: i,c,B=60,6,[] while i*c>0: t,d=I().split() d=int(d) for a in A[-N:]: if t==a:d=min(d,K) i,c=i-d,c-1 B+=[t] if i<0: P(6-c-1),B.pop() else:P(6-c) for b in B:A+=[b] while c>0: t,d=I().split() c-=1 A+=[t]