import sys input = sys.stdin.readline N = int(input()) H = list(map(int, input().split())) T = list(map(int, input().split())) HT = [] for i in range(N): HT.append((-T[i], H[i], i)) HT.sort() M = 18 dp = [-1] * (N * M) from bisect import * from collections import * inf = 10 ** 18 minv = defaultdict(lambda : inf) L = [-inf] def f(a, b): return a * N + b for t, h, i in HT: h = -h ind = bisect_left(L, t) if ind != len(L): dp[i] = minv[L[ind]] if h > L[-1]: L.append(h) minv[h] = i for i in range(1, M): for j in range(N): if dp[f(i-1,j)] == -1: continue dp[f(i,j)] = dp[f(i-1,dp[f(i-1,j)])] def check(m, A, B): now = A for i in range(M): if (m >> i) & 1: now = dp[f(i,now)] if now == -1: return 2 return T[now] >= H[B] Q = int(input()) for _ in range(Q): A, B = map(int, input().split()) A, B = A - 1, B - 1 if H[B] <= T[A]: print(1) continue yes = N + 1 no = 0 while yes - no != 1: mid = (yes + no)//2 flag = check(mid, A, B) if flag: yes = mid else: no = mid if flag == 2: print(-1) else: print(yes + 1)