// Copyright (C) 2017 __debug.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
using std::pair;
using std::vector;
using std::string;
typedef long long LL;
typedef pair<int, int> Pii;
const int oo = 0x3f3f3f3f;
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
std::ifstream t("/proc/self/status");
return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
f = (ch == '-' ? -1 : 1);
for (x = 0; isdigit(ch); ch = getchar())
x = 10 * x + ch - '0';
return x *= f;
}
template<typename T> void write(T x)
{
if (x == 0) {
putchar('0');
return;
}
if (x < 0) {
putchar('-');
x = -x;
}
static char s[20];
int top = 0;
for (; x; x /= 10)
s[++top] = x % 10 + '0';
while (top)
putchar(s[top--]);
}
// EOT
const int MAXN = 1e5 + 5;
int N, Q;
Pii A[MAXN];
int C[MAXN];
Pii QRY[MAXN];
void input()
{
read(N);
for (int i = 0; i < N; ++i) {
read(A[i].x); read(A[i].y);
}
for (int i = 0; i <= N; ++i) {
read(C[i]);
}
read(Q);
for (int i = 1; i <= Q; ++i) {
read(QRY[i].x); read(QRY[i].y);
}
}
void solve()
{
static int hash[MAXN];
std::sort(C, C + N + 1);
std::copy(C, C + N + 1, hash);
int hashsize = std::unique(hash, hash + N + 1) - hash;
for (int i = 0; i <= N; ++i) {
C[i] = std::lower_bound(hash, hash + hashsize, C[i]) - hash;
}
for (int i = 0; i < N; ++i) {
A[i].x = std::lower_bound(hash, hash + hashsize, A[i].x) - hash;
A[i].y = std::lower_bound(hash, hash + hashsize, A[i].y) - hash;
}
for (int i = 1; i <= Q; ++i) {
QRY[i].x = std::lower_bound(hash, hash + hashsize, QRY[i].x) - hash;
QRY[i].y = std::lower_bound(hash, hash + hashsize, QRY[i].y) - hash;
}
// for (int i = 0; i < N; ++i) {
// printf("%d %d\n", A[i].x, A[i].y);
// }
// puts("");
// for (int i = 1; i <= Q; ++i) {
// printf("%d %d\n", QRY[i].x, QRY[i].y);
// }
static int val[MAXN];
for (int i = 0; i <= N; ++i) {
--val[C[i]];
}
for (int i = 0; i < N; ++i) {
++val[A[i].x];
}
for (int i = 0; i < hashsize; ++i) {
val[i + 1] += val[i];
}
// for (int i = 0; i < hashsize; ++i) {
// printf("%d ", val[i]);
// }
// puts("");
static int dec[MAXN], inc[MAXN];
__gnu_pbds::priority_queue<Pii, std::greater<Pii> > q0;
__gnu_pbds::priority_queue<Pii> q1;
std::multiset<Pii> unused;
vector<Pii> interval;
for (int i = 0; i < N; ++i) {
if (A[i].x > A[i].y) {
interval.push_back(A[i]);
unused.insert(MP(A[i].y, A[i].x));
}
}
std::sort(ALL(interval), std::greater<Pii>());
int cur = 0;
for (int i = hashsize - 1, j = 0, cnt = 0; i >= 0; --i) {
for (; j < SZ(interval) && interval[j].x > i; ++j) {
q0.push(MP(interval[j].y, interval[j].x));
}
val[i] += cnt;
while (SZ(q0) && val[i] < -1) {
Pii t = q0.top(); q0.pop();
if (t.x > i) break;
unused.erase(unused.find(t));
++val[i]; ++cnt; ++dec[t.x];
++inc[i + 1]; --inc[t.y];
++cur;
}
cnt -= dec[i];
if (val[i] < -1) {
for (int k = 1; k <= Q; ++k) {
puts("-1");
}
return;
}
}
for (int i = 0, cnt = 0; i < hashsize; ++i) {
val[i] += cnt += inc[i];
}
// for (int i = 0; i < hashsize; ++i) {
// printf("%d ", val[i]);
// }
// puts("");
static int ans[MAXN];
memset(dec, 0, sizeof(dec));
ans[0] = cur;
for (int i = 1, cnt = 0; i <= hashsize; ++i) {
while (SZ(unused) && unused.begin()->x < i) {
q1.push(MP(unused.begin()->y, unused.begin()->x));
// printf("use %d %d\n", unused.begin()->x, unused.begin()->y);
unused.erase(unused.begin());
}
val[i - 1] += cnt;
if (SZ(q1) && val[i - 1] < 0) {
Pii t = q1.top(); q1.pop();
// printf("i=%d, t.x=%d\n", i, t.x);
if (t.x >= i) {
// printf("adddec %d\n", t.x);
++val[i - 1]; ++cnt; ++dec[t.x];
++cur;
}
}
cnt -= dec[i];
if (val[i - 1] < 0) {
for (; i <= hashsize; ++i) {
ans[i] = +oo;
}
break;
}
ans[i] = cur;
}
// for (int i = 0; i <= hashsize; ++i) {
// printf("ans(%d)=%d\n", i, ans[i]);
// }
for (int i = 1; i <= Q; ++i) {
int t = std::min(ans[QRY[i].x], ans[QRY[i].y] + 1);
if (t == +oo)
puts("-1");
else
printf("%d\n", N + 1 - t);
}
}
int main()
{
#ifdef __DEBUG
freopen("F.in", "r", stdin);
freopen("F.out", "w", stdout);
#endif
input();
solve();
return 0;
}
// 易挑锦妇机中字。难得玉人心下事。
// -- 刘克庄《玉楼春·戏林推》