#include <bits/stdc++.h> //#include <atcoder/modint> using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* 町iにいる時、H_j<=T_i以下であるような町jのうち、T_jが最大であるものに行くのが最適でそれ以外は考慮しなくて良い。 よって、各町からk回移動したあとの行き先がダブリングによりO(log k)で求まる。 クエリには、Aからスタートして初めてTがH_B以上となる回数をO(log N)で求める。 */ int N, mx=-1, argmx=-1; cin >> N; vector<int> H(N), T(N); vector<pair<int, int>> v; queue<pair<int, int>> que; vector dp(20, vector<int>(N)); for (int i=0; i<N; i++) cin >> H[i]; for (int i=0; i<N; i++){ cin >> T[i]; v.push_back({H[i], i}); } sort(v.begin(), v.end()); for (auto &z : v) que.push(z); v.clear(); for (int i=0; i<N; i++) v.push_back({T[i], i}); sort(v.begin(), v.end()); for (int i=0; i<N; i++){ while(!que.empty() && que.front().first <= v[i].first){ int x, y; tie(x, y) = que.front(); que.pop(); if (T[y] > mx){ mx = T[y]; argmx = y; } } dp[0][v[i].second] = argmx; } for (int i=1; i<20; i++){ for (int j=0; j<N; j++){ if (dp[i-1][j] != -1) dp[i][j] = dp[i-1][dp[i-1][j]]; } } int Q, s, t; cin >> Q; while(Q--){ cin >> s >> t; s--; t--; int x = dp[19][s], ans=0; if (H[t] <= T[s]) cout << 1 << '\n'; else if (x == -1 || T[x] < H[t]) cout << -1 << '\n'; else{ for (int i=19; i>=0; i--){ if (T[dp[i][s]] < H[t]){ s = dp[i][s]; ans += 1<<i; } } s = dp[0][s]; if (s == t) cout << ans+1 << '\n'; else cout << ans+2 << '\n'; } } return 0; }