#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 100;
long long k, m, n, r[maxn], a[maxn], c[maxn], ans[maxn], d[maxn][2], l, t[maxn],
    maxx[4 * maxn];
pair<pair<long long, long long>, long long> rm[maxn], am[maxn];
pair<pair<long long, long long>, pair<long long, long long> > q[maxn];
pair<long long, long long> b[maxn];
struct fen {
  long long tree[maxn];
  fen() { memset(tree, 0, sizeof tree); }
  long long C(long long x) {
    long long ret = 0;
    for (; x > 0; x -= x & (-x)) ret += tree[x];
    return ret;
  }
  long long sum(long long i, long long j) { return C(j) - C(i - 1); }
  void update(long long x, long long val) {
    for (; x < maxn; x += x & (-x)) tree[x] += val;
  }
};
void update(long long x, long long val, long long l = 1, long long r = n,
            long long cnt = 1) {
  if (x < l || r < x) return;
  if (l == r) {
    maxx[cnt] = val;
    return;
  }
  long long med = (l + r) / 2;
  update(x, val, l, med, 2 * cnt);
  update(x, val, med + 1, r, 2 * cnt + 1);
  maxx[cnt] = max(maxx[2 * cnt], maxx[2 * cnt + 1]);
}
long long f_max(long long x, long long y, long long l = 1, long long r = n,
                long long cnt = 1) {
  if (y < l || r < x) return 0;
  if (x <= l && r <= y) return maxx[cnt];
  long long med = (l + r) / 2;
  return max(f_max(x, y, l, med, 2 * cnt),
             f_max(x, y, med + 1, r, 2 * cnt + 1));
}
pair<long long, long long> help(long long i) {
  long long x = q[i].second.first, y = q[i].second.second;
  x = c[x];
  y = c[y];
  if (x > y) swap(x, y);
  long long u1 = max(d[x][0], d[y][0]);
  long long u2 = min(d[x][1], d[y][1]);
  if (u2 < u1) return make_pair(-1, -1);
  return make_pair(u1, u2);
}
fen f;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> r[i];
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    q[i] = make_pair(make_pair(max(r[x], r[y]), i), make_pair(x, y));
  }
  for (int i = 1; i <= n; i++) {
    am[i] = make_pair(make_pair(a[i], r[i]), i);
    rm[i] = make_pair(make_pair(r[i], a[i]), i);
  }
  sort(am + 1, am + n + 1);
  sort(rm + 1, rm + n + 1);
  sort(a + 1, a + n + 1);
  sort(q + 1, q + m + 1);
  for (int i = 1; i <= n; i++) {
    long long x = am[i].second;
    long long k1 = lower_bound(a + 1, a + n + 1, a[i] - k) - a;
    long long k2 = upper_bound(a + 1, a + n + 1, a[i] + k) - a;
    k2--;
    d[i][0] = k1;
    d[i][1] = k2;
    c[x] = i;
  }
  l = 1;
  for (int i = 1; i <= n;) {
    while (rm[i + 1].first.first == rm[i].first.first) {
      long long x1 = rm[i].second;
      long long x2 = c[x1];
      f.update(x2, 1);
      i++;
    }
    long long x1 = rm[i].second;
    long long x2 = c[x1];
    f.update(x2, 1);
    for (int j = l; j <= i; j++) {
      long long x1 = rm[j].second;
      long long x2 = c[x1];
      t[x2] = f.sum(d[x2][0], d[x2][1]);
    }
    i++;
    l = i;
  }
  l = n;
  for (int i = m; i >= 1; i--) {
    while (rm[l].first.first >= q[i].first.first) {
      long long x1 = rm[l].second;
      long long x2 = c[x1];
      update(x2, t[x2]);
      l--;
    }
    pair<long long, long long> h = help(i);
    if (h.first == -1)
      ans[q[i].first.second] = -1;
    else
      ans[q[i].first.second] = f_max(h.first, h.second);
    if (!ans[q[i].first.second]) ans[q[i].first.second] = -1;
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << endl;
  return 0;
}
