import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log N = int(input()) H = list(map(int,input().split())) T = list(map(int,input().split())) val_set = set(H) | set(T) comp = {e:i for i,e in enumerate(sorted(val_set))} M = len(comp) H = [comp[h] for h in H] T = [comp[t] for t in T] K = 19 highest = [[0]*M for i in range(K)] for i in range(N): highest[0][H[i]] = max(highest[0][H[i]],T[i]) for k in range(1,K+1): cum_max = [0] * M for i in range(M): cum_max[i] = highest[k-1][i] for i in range(1,M): cum_max[i] = max(cum_max[i],cum_max[i-1]) highest[k-1] = cum_max if k == K: continue for i in range(N): highest[k][H[i]] = max(highest[k][H[i]],cum_max[highest[k-1][T[i]]]) for _ in range(int(input())): a,b = map(int,input().split()) a,b = a-1,b-1 if a == b: print(0) continue a = T[a] if a >= H[b]: print(1) continue if highest[K-1][a] < H[b]: print(-1) continue res = 1 for k in range(K)[::-1]: if highest[k][a] < H[b]: res += 1<