from sys import stdin input = stdin.readline from bisect import bisect_left, bisect_right N = int(input()) H = list(map(int, input().split())) T = list(map(int, input().split())) Q = int(input()) query = [list(map(int, input().split())) for _ in range(Q)] HT = sorted([(H[i], T[i]) for i in range(N)], key=lambda x:x[0]) A, B = map(list, zip(*HT)) for i in range(1, N): B[i] = max(B[i-1], B[i]) dp = [[-1]*N] idx = 0 for i, b in enumerate(B): while idx < N and A[idx] <= b: idx += 1 if 1 <= idx: dp[-1][i] = idx-1 for _ in range(19): dp.append([-1]*N) for i in range(N): if dp[-2][i] == -1: continue dp[-1][i] = dp[-2][dp[-2][i]] for s, t in query: s, t = s-1, t-1 if H[t] <= T[s]: print(1) continue b = bisect_right(A, T[s])-1 if b == -1: print(-1) continue gb = bisect_left(A, H[t]) ans = 1 for i in reversed(range(20)): if dp[i][b] != -1 and dp[i][b] < gb: ans += 1<