#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#define MN 100000
#define pa pair<int,int>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
vector<int> v[MN+5],V[MN+5];
priority_queue<pa> q;priority_queue<int,vector<pa>,greater<pa> >Q;
int n,num,c[MN+5],a[MN+5],b[MN+5],L[MN+5],s[MN+5],ans[MN+5],now,S[MN+5],flag=1,vis[MN+5],add[MN+5];
/*
struct Tree{int l,r;pa mn;int val;}T[MN*4+5];
void Build(int x,int l,int r)
{
    if((T[x].l=l)==(T[x].r=r)){T[x].mn=make_pair(s[l],l);return;}
    int mid=l+r>>1;
    Build(x<<1,l,mid);Build(x<<1|1,mid+1,r);
    T[x].mn=min(T[x<<1].mn,T[x<<1|1].mn);
}
inline void Mark(int x,int v){T[x].val+=v;T[x].mn.first+=v;}
inline void pushdown(int x){Mark(x<<1,T[x].val);Mark(x<<1|1,T[x].val);T[x].val=0;}
void Modify(int x,int l,int r,int v)
{
    if(T[x].l==l&&T[x].r==r) return Mark(x,v);
    int mid=T[x].l+T[x].r>>1;
    if(T[x].val) pushdown(x);
    if(r<=mid) Modify(x<<1,l,r,v);
    else if(l>mid) Modify(x<<1|1,l,r,v);
    else Modify(x<<1,l,mid,v),Modify(x<<1|1,mid+1,r,v);
    T[x].mn=min(T[x<<1].mn,T[x<<1|1].mn);
}
pa Query(int x,int l,int r)
{
    if(T[x].l==l&&T[x].r==r)return T[x].mn;
    int mid=T[x].l+T[x].r>>1;
    if(T[x].val) pushdown(x);
    if(r<=mid) return Query(x<<1,l,r);
    else if(l>mid) return Query(x<<1|1,l,r);
    else return min(Query(x<<1,l,mid),Query(x<<1|1,mid+1,r));
}*/
int main()
{
    n=read()+1;
    for(int i=1;i<n;++i) a[i]=read(),b[i]=min(a[i],read());
    for(int i=1;i<=n;++i) L[i]=c[i]=read();
    sort(L+1,L+n+1);num=unique(L+1,L+n+1)-L-1;
    for(int i=1;i<=n;++i) --s[lower_bound(L+1,L+num+1,c[i])-L];
    for(int i=1;i<n;++i)
    {
        a[i]=lower_bound(L+1,L+num+1,a[i])-L;
        b[i]=lower_bound(L+1,L+num+1,b[i])-L;
        ++s[a[i]];
        if(b[i]<a[i]) v[a[i]-1].push_back(i),V[b[i]].push_back(i);
    }
    for(int i=1;i<=num;++i) s[i]+=s[i-1];
    for(int i=num,V=0;i;--i)
    {
        s[i]+=(V+=S[i]);S[i]=0;
        for(int j=0;j<v[i].size();++j) Q.push(make_pair(b[v[i][j]],v[i][j]));
        while(s[i]<-1)
        {
            if(Q.empty()||Q.top().first>i) break;
            int use=Q.top().second;Q.pop();vis[use]=1;
            ++now;++V;++s[i];--S[b[use]-1];
            ++add[i+1];--add[a[use]];
        }
        if(s[i]<-1) flag=0;
    }
    ans[0]=flag?now:1e9;
    for(int i=1;i<=num;++i) s[i]+=(add[i]+=add[i-1]);
    for(int i=1,v=0;i<=num;++i)
    {
        s[i]+=(v+=S[i]);S[i]=0;
        for(int j=0;j<V[i].size();++j) if(!vis[V[i][j]]) q.push(make_pair(a[V[i][j]]-1,V[i][j]));
        while(s[i]<0)
        {
            if(q.empty()||q.top().first<i) break;
            int use=q.top().second;q.pop();vis[use]=1;
            ++now;++v;++s[i];--S[a[use]];
        }
        if(s[i]<0) flag=0;
        ans[i]=flag?now:1e9;
    }
    for(int i=num;i--;)ans[i]=min(ans[i],ans[i+1]);
    int qq=read();while(qq--)
    {
        int s=read(),t=read();
        int res=min(ans[lower_bound(L+1,L+num+1,s)-L-1],ans[lower_bound(L+1,L+num+1,t)-L-1]+1);
        printf("%d\n",res>n?-1:n-res);
    }
    return 0;
}


Measured memory_bytes: 18168