#include <bits/stdc++.h>
using namespace std;
struct segment_tree {
  long long n;
  vector<vector<long long>> st;
  segment_tree(long long n) : n(n), st(4 * n, vector<long long>(0)) {}
  void build(const vector<long long> &a) { build(1, 0, n, a); }
  long long query(long long b, long long e, long long k) {
    return query(1, 0, n, b, e, k);
  }

 private:
  void build(long long node, long long b, long long e,
             const vector<long long> &a) {
    if (b + 1 == e) {
      st[node].push_back(a[b]);
      return;
    }
    long long m = (b + e) >> 1, l = node << 1, r = l | 1;
    build(l, b, m, a);
    build(r, m, e, a);
    st[node].resize(e - b);
    merge(st[l].begin(), st[l].end(), st[r].begin(), st[r].end(),
          st[node].begin());
  }
  long long query(long long node, long long b, long long e, long long bb,
                  long long ee, long long k) {
    if (bb <= b && e <= ee) {
      return upper_bound(st[node].begin(), st[node].end(), k) -
             st[node].begin();
    }
    long long m = (b + e) >> 1, l = node << 1, r = l | 1;
    long long ans = 0;
    if (bb < m) ans += query(l, b, m, bb, min(m, ee), k);
    if (m < ee) ans += query(r, m, e, max(bb, m), ee, k);
    return ans;
  }
};
struct segment_tree_max {
  long long n;
  vector<long long> st, lazy;
  segment_tree_max(long long n) : n(n), st(4 * n), lazy(4 * n, -1) {}
  void update(long long b, long long e, long long k) {
    update(1, 0, n, b, e, k);
  }
  long long query(long long b, long long e) { return query(1, 0, n, b, e); }

 private:
  void push(long long node, long long val) {
    st[node] = max(st[node], val);
    lazy[node] = val;
  }
  void update(long long node, long long b, long long e, long long bb,
              long long ee, long long k) {
    if (bb <= b && e <= ee) {
      push(node, k);
      return;
    }
    long long m = (b + e) >> 1, l = node << 1, r = l | 1;
    if (lazy[node] != -1) {
      push(l, lazy[node]);
      push(r, lazy[node]);
      lazy[node] = -1;
    }
    if (bb < m) update(l, b, m, bb, min(ee, m), k);
    if (m < ee) update(r, m, e, max(bb, m), ee, k);
    st[node] = max(st[l], st[r]);
  }
  long long query(long long node, long long b, long long e, long long bb,
                  long long ee) {
    if (bb <= b && e <= ee) return st[node];
    long long m = (b + e) >> 1, l = node << 1, r = l | 1;
    if (lazy[node] != -1) {
      push(l, lazy[node]);
      push(r, lazy[node]);
      lazy[node] = -1;
    }
    long long ans = -1;
    if (bb < m) ans = max(ans, query(l, b, m, bb, min(ee, m)));
    if (m < ee) ans = max(ans, query(r, m, e, max(bb, m), ee));
    return ans;
  }
};
bool cmp(const pair<long long, pair<long long, long long>> &a,
         const pair<long long, pair<long long, long long>> &b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second < b.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, pair<long long, long long>>> pts(n);
  vector<long long> x(n), y(n), pos(n);
  for (long long i = 0; i < n; i++) cin >> y[i];
  for (long long i = 0; i < n; i++) cin >> x[i];
  for (long long i = 0; i < n; i++) pts[i] = {x[i], {y[i], i}};
  sort(pts.begin(), pts.end());
  for (long long i = 0; i < n; i++) pos[pts[i].second.second] = i;
  vector<long long> coord = x;
  sort(coord.begin(), coord.end());
  segment_tree st(n);
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) a[i] = pts[i].second.first;
  st.build(a);
  vector<long long> sz(n);
  for (long long i = 0; i < n; i++) {
    auto cur = pts[i];
    long long b =
        upper_bound(coord.begin(), coord.end(), cur.first + k) - coord.begin();
    long long a =
        lower_bound(coord.begin(), coord.end(), cur.first - k) - coord.begin();
    sz[i] = st.query(a, b, cur.second.first);
  }
  long long q;
  cin >> q;
  vector<pair<long long, pair<long long, long long>>> query(q);
  vector<long long> pos_query(q);
  vector<pair<long long, long long>> real_query(q);
  for (long long i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    if (y[a] >= y[b])
      query[i] = {y[a], {a, i}};
    else
      query[i] = {y[b], {b, i}};
    real_query[i] = {a, b};
  }
  sort(query.begin(), query.end(), cmp);
  for (long long i = 0; i < q; i++) pos_query[query[i].second.second] = i;
  segment_tree_max st_max(n);
  vector<long long> ans(q);
  vector<pair<long long, long long>> coordy(n);
  for (int i = 0; i < n; i++) coordy[i] = {y[i], i};
  sort(coordy.begin(), coordy.end());
  int ptr = n - 1;
  for (long long i = 0; i < q; i++) {
    auto cur = query[i];
    while (ptr > 0 && coordy[ptr].first >= cur.first) {
      long long p = pos[coordy[ptr].second];
      long long X = x[coordy[ptr].second];
      long long b = upper_bound(coord.begin(), coord.end(), X) - coord.begin();
      long long a = lower_bound(coord.begin(), coord.end(), X) - coord.begin();
      st_max.update(a, b, sz[p]);
      ptr--;
    }
    long long ps = cur.second.second;
    long long a = real_query[ps].first;
    long long b = real_query[ps].second;
    long long X = max(x[a] - k, x[b] - k);
    long long Y = min(x[a] + k, x[b] + k);
    b = upper_bound(coord.begin(), coord.end(), Y) - coord.begin();
    a = lower_bound(coord.begin(), coord.end(), X) - coord.begin();
    ans[i] = st_max.query(a, b);
    if (ans[i] < 2) ans[i] = -1;
  }
  for (long long i = 0; i < q; i++) cout << ans[pos_query[i]] << '\n';
  return 0;
}
