#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define INF (ll)1e9
#define N 200005
struct Edge{
ll u,v,w;
};
ll n;
ll dist[3][N*5];
vector<ll> g[N*5];
vector<Edge> E;
void addEdge(ll u,ll v,ll w){
g[u].pb((ll)E.size());
E.pb({u,v,w});
}
void build(ll id,ll l,ll r){
if(l==r){
addEdge(l,id+n,0);
return;
}
ll mid=(l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
addEdge(id*2+n,id+n,0);
addEdge(id*2+n+1,id+n,0);
}
void update(ll id,ll l,ll r,ll u,ll v,ll x){
if(l>=u and r<=v){
addEdge(id+n,x,1);
return;
}
ll mid=(l+r)/2;
if(u<=mid)update(id*2,l,mid,u,v,x);
if(v>mid)update(id*2+1,mid+1,r,u,v,x);
}
void bfs_01(ll id,ll source){
for(ll i=1; i<=n*5; i++)dist[id][i]=INF*INF;
dist[id][source]=0;
deque<ll> q;
q.push_front(source);
while(!q.empty()){
ll x=q.front();
q.pop_front();
for(ll ide:g[x]){
ll v=E[ide].u^E[ide].v^x;
if(dist[id][v]>dist[id][x]+E[ide].w){
dist[id][v]=dist[id][x]+E[ide].w;
if(!E[ide].w)q.push_front(v);
else q.pb(v);
}
}
}
}
void solve(){
cin>>n;
for(ll i=1; i<=n; i++){
ll l,r;
cin>>l>>r;
update(1,1,n,l,r,i);
}
build(1,1,n);
bfs_01(0,1);
bfs_01(1,n);
priority_queue<pair<ll,ll>> pq;
for(ll i=1; i<=n*5; i++)dist[2][i]=INF*INF;
for(ll i=1; i<=n; i++){
if(max(dist[0][i],dist[1][i])<INF*INF){
dist[2][i]=dist[0][i]+dist[1][i]-(i!=1 and i!=n);
pq.push({-dist[2][i],i});
}
}
while(!pq.empty()){
pair<ll,ll> eq=pq.top();
pq.pop();
ll x=eq.ss;
if(-eq.ff>dist[2][x])continue;
for(ll ide:g[x]){
ll v=E[ide].u^E[ide].v^x;
if(dist[2][v]>dist[2][x]+E[ide].w){
dist[2][v]=dist[2][x]+E[ide].w;
pq.push({-dist[2][v],v});
}
}
}
ll q;
cin>>q;
while(q--){
ll u;
cin>>u;
if(dist[2][u]>=INF*INF)cout<<-1<<'\n';
else cout<<dist[2][u]<<'\n';
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
ll t=1;
// cin>>t;
while(t--)solve();
return 0;
}