I,R=input,range def J(): return map(int,I().split()) N,A=J() X=list(J()) T=R(int(I())) W=[list(J())for t in T] Y=set(X) for w in W:Y.add(w[0]),Y.add(w[1]) s=0 Z={} for y in sorted(Y):Z[y],s=s,s+1 X=[Z[x]for x in X] W=[[Z[x]for x in w]for w in W] M=548 A=[-1]*s B=[-1]*M for t in T: l,r=W[t][0],W[t][1]+1 m=(l+M-1)//M n=max(m,r//M) a=min(m*M,r) for i in R(l,a):A[i]=max(A[i],t+1) for i in R(m,n):B[i]=max(B[i],t+1) for i in R(max(a,n*M),r):A[i]=max(A[i],t+1) for x in X:print(max(A[x],B[x//M]))