import sys input = sys.stdin.readline n = int(input()) H = list(map(int, input().split())) T = list(map(int, input().split())) X = H + T X = sorted(set(X)) dic = {X[i]: i for i in range(len(X))} H = [dic[h] for h in H] T = [dic[t] for t in T] le = len(X) m = 20 nex = [[i for i in range(le)] for _ in range(m)] for h, t in zip(H, T): nex[0][h] = max(nex[0][h], t) for i in range(1, le): nex[0][i] = max(nex[0][i], nex[0][i - 1]) for i in range(1, m): for j in range(le): nex[i][j] = nex[i - 1][nex[i - 1][j]] Q = int(input()) for _ in range(Q): a, b = map(int, input().split()) a -= 1 b -= 1 if T[a] >= H[b]: print(1) continue ans = 1 t = T[a] for i in range(m - 1, -1, -1): nt = nex[i][t] if nt < H[b]: t = nt ans += 1 << i ans += 1 nt = nex[0][t] if nt >= H[b]: print(ans) else: print(-1)