n,a=map(int,input().split()) x=list(map(int,input().split())) for i in range(n): x[i]=(x[i],i) x.sort() from atcoder import lazysegtree from bisect import bisect_left,bisect_right st=lazysegtree.LazySegTree( max, -1, max, max, -1, [-1]*n) t=int(input()) for i in range(t): l,r=map(int,input().split()) l=bisect_left(x,(l,0)) r=bisect_right(x,(r,n)) st.apply(l,r,i+1) ans=[0]*n for i in range(n): y=st.get(i) ans[x[i][1]]=y print(*ans,sep="\n")