from sys import stdin input = stdin.readline n = int(input()); l = n.bit_length() h = list(map(int,input().split())) t = list(map(int,input().split())) itov = sorted(set(h)|set(t)); m = len(itov) vtoi = {v:i for i,v in enumerate(itov)} for i in range(n): h[i] = vtoi[h[i]]; t[i] = vtoi[t[i]] tele = list(range(m)); ht = [(u,v) for u,v in zip(h,t)] for u,v in sorted(ht): tele[u] = max(tele[u],v) for i in range(m-1): tele[i+1] = max(tele[i+1],tele[i]) doub = [tele]+[[0]*m for _ in range(l)] for i in range(l): for j in range(m): doub[i+1][j] = max(doub[i][doub[i][j]],doub[i][j]) for _ in range(int(input())): a,b = map(int,input().split()) x = t[a-1]; y = h[b-1]; ans = 1 if y>doub[l][x]: print(-1); continue for i in range(l-1,-1,-1): if doub[i][x]