#include using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i>n; vector> ht(n,vector(3)); rep(i,n) cin>>ht.at(i).at(0); rep(i,n) cin>>ht.at(i).at(1); rep(i,n) ht.at(i).at(2)=i; sort(ht.begin(),ht.end()); vector p(n); rep(i,n) p.at(ht.at(i).at(2))=i; vector cnd(n+1,-1); vector cph(n); rep(i,n) cph.at(i)=ht.at(i).at(0); rep(i,n){ auto it=upper_bound(cph.begin(),cph.end(),ht.at(i).at(1)); cnd.at(i+1)=max(cnd.at(i),int(it-cph.begin()-1)); } vector> cvv; { int nw=0; while(nw cnd2; while(nw!=cnd.at(nw+1)){ cnd2.push_back(nw); nw=cnd.at(nw+1); } cnd2.push_back(nw); cvv.push_back(cnd2); for(;nw rcv; rep(i,cvv.size()){ rcv.push_back(cvv.at(i).at(0)); } int q; cin>>q; rep(Qi,q){ int a,b; cin>>a>>b; a--; b--; int na=p.at(a),nb=p.at(b); int ans=1; na=upper_bound(cph.begin(),cph.end(),ht.at(na).at(1))-cph.begin()-1; if(na