#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n), b(n);
        for (int i = 0; i < n; i ++) scanf("%d%d", &a[i], &b[i]);
        vector<int> c(n + 1);
        for (int i = 0; i < n + 1; i ++) scanf("%d", &c[i]);
        sort(c.begin(), c.end());
        auto convert = [&](int x) {
                auto d = lower_bound(c.begin(), c.end(), x) - c.begin();
                return d;
        };
        vector<vector<int>> g(n + 1);
        for (int i = 0; i < n; i ++) {
                a[i] = convert(a[i]);
                b[i] = convert(b[i]);
                if (a[i] > b[i]) { 
                        g[a[i] - 1].push_back(b[i]);
                }
        }
        vector<int> sum(n + 1, 0);
        for (int i = 0; i < n + 1; i ++) sum[i] --;
        for (int i = 0; i < n; i ++) sum[a[i]] ++;
        vector<int> realsum = sum;
        vector<int> revsum(n + 1, 0);
        for (int i = 0; i < n; i ++) sum[i + 1] += sum[i];
        revsum[n] = sum[n];
        for (int i = n; i > 0; i --) revsum[i - 1] = sum[i - 1] - sum[i];
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> seg;
        vector<pair<int, int>> used;
        bool ok = true;
        for (int i = n; i >= 0; i --) {
                if (i < n) revsum[i] += revsum[i + 1];
                for (auto to : g[i]) {
                        seg.emplace(to, i);
                }
                while (revsum[i] < -1 && !seg.empty()) {
                        pair<int, int> get = seg.top();
                        seg.pop();
                        int left = get.first;
                        revsum[i] ++;
                        if (left > 0) revsum[left - 1] --;
                        used.push_back(get);
                }
                if (revsum[i] < -1) {
                        ok = false;
                }
        }
        vector<vector<int>> rest(n + 1);
        while (!seg.empty()) {
                pair<int, int> get = seg.top();
                seg.pop();
                rest[get.first].push_back(get.second + 1);
        }
        for (auto it : used) {
                realsum[it.first] ++;
                realsum[it.second + 1] --;
        }
        int necessary = (int) used.size();
        priority_queue<pair<int, int>> seg2;
        vector<int> cnt(n + 1);
        for (int i = 0; i < n + 1; i ++) {
                if (i > 0) { 
                        realsum[i] += realsum[i - 1];
                        cnt[i] += cnt[i - 1];
                }
                for (auto to : rest[i]) {
                        seg2.emplace(to, i);
                }
                while (realsum[i] < 0 && !seg2.empty()) {
                        pair<int, int> get = seg2.top();
                        seg2.pop();
                        int right = get.first;
                        //add 1 to [i, right) (virtually)
                        realsum[i] ++;
                        realsum[right] --;
                        cnt[i] ++;
                }
                if (realsum[i] < 0) {
                        cnt[i] = 1 << 30;
                }
        }
        int q;
        scanf("%d", &q);
        while (q --) {
                int d, e;
                scanf("%d%d", &d, &e);
                if (!ok) {
                        printf("%d\n", -1);
                        continue;
                }
                d = convert(d);
                e = convert(e);
                int res1 = (d == 0 ? 0 : cnt[d - 1]);
                int res2 = (e == 0 ? 1 : cnt[e - 1] + 1);
                int res = min(res1, res2);
                int ans = n - necessary - res + 1;
                if (ans < 0) printf("%d\n", -1);
                else printf("%d\n", ans);
        }                                      
        return 0;
}


Measured memory_bytes: 15216