I,R,P=input,range,print def J(): return map(int,I().split()) N,K,Q=J() A=[] M=0 for q in R(Q): t=I() if t=="1": A+=[I()] M+=1 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] P([6-c,6-c-1][i<0]) while c>0: t,d=I().split() B+=[t] c-=1 for b in B:A+=[b]