import sys input = sys.stdin.readline from collections import * from bisect import * N = int(input()) H = list(map(int, input().split())) T = list(map(int, input().split())) HTI = [(H[i], T[i], i) for i in range(N)] HTI.sort() H = [Hi for Hi, _, _ in HTI] T = [Ti for _, Ti, _ in HTI] idx = [-1]*N for i in range(N): idx[HTI[i][2]] = i to = [0]*(N+1) for v in range(N): to[v+1] = bisect_right(H, T[v]) dp = [[0]*(N+1) for _ in range(30)] for v in range(1, N+1): dp[0][v] = max(dp[0][v-1], to[v]) for i in range(1, 30): for v in range(N+1): dp[i][v] = dp[i-1][dp[i-1][v]] Q=int(input()) for _ in range(Q): x,y=map(int, input().split()) s,g=idx[x-1],idx[y-1] if T[s]>=H[g]: print(1) continue c=2 s=to[s+1] for i in range(29,-1,-1): if dp[i][s]=N: print(-1) else: print(c)