N=int(input()) H=list(map(int, input().split())) T=list(map(int, input().split())) A=[(0,0,0)] for i in range(N): A.append((H[i],T[i],i+1)) A=sorted(A) D={} for i in range(N+1): D[A[i][2]]=i HH=[0]+H HH=sorted(HH) import bisect a=len(A) b=a.bit_length() dp=[[0]*a for _ in range(b)] for i in range(a): if i==0: dp[0][0]=0 h=0 else: bb=A[i][1] h=max(h,bb) d=bisect.bisect_right(HH,h)-1 dp[0][i]=max(i,d) for k in range(1,b): for i in range(a): dp[k][i] = dp[k-1][dp[k-1][i]] Q=int(input()) for _ in range(Q): x,y=map(int, input().split()) if T[x-1]>=H[y-1]: print(1) continue s,g=D[x],D[y] c=0 for i in range(b-1,-1,-1): if dp[i][s]=2**b: print(-1) else: print(c)