#include <bits/stdc++.h>
using namespace std;
struct Mbr {
  int id, age, val;
} mbr[100050];
struct Query {
  int x, y, id, mr, out;
} query[100050];
struct Node {
  int l, r, ms, ma, sum;
} node[100050 << 2];
struct Xyz {
  int x, y, z;
};
int n, lim, q, pos[100050], ll[100050], rr[100050], size[100050];
bool cmp1(const Mbr &a, const Mbr &b) { return a.age < b.age; }
bool cmp2(const Mbr &a, const Mbr &b) { return a.val < b.val; }
bool cmp3(const Query &a, const Query &b) { return a.mr < b.mr; }
bool cmp4(const Query &a, const Query &b) { return a.id < b.id; }
void to_Xyz(Xyz &xyz, const Node &_node) {
  xyz.x = max(xyz.x, _node.ms);
  xyz.y = max(xyz.y, _node.ma);
  xyz.z += _node.sum;
}
void to_Xyz(Xyz &xyz, const Xyz &_node) {
  xyz.x = max(xyz.x, _node.x);
  xyz.y = max(xyz.y, _node.y);
  xyz.z += _node.z;
}
void up(int k) {
  node[k].ma = max(node[k << 1].ma, node[(k << 1) ^ 1].ma);
  node[k].ms = max(node[k << 1].ms, node[(k << 1) ^ 1].ms);
  node[k].sum = node[k << 1].sum + node[(k << 1) ^ 1].sum;
}
void build(int k, int l, int r) {
  node[k].l = l;
  node[k].r = r;
  if (l < r) {
    int mid = (l + r) >> 1;
    build(k << 1, l, mid);
    build((k << 1) ^ 1, mid + 1, r);
    up(k);
  } else {
    node[k].ma = mbr[l].age;
    node[k].ms = -2010000000;
    node[k].sum = 0;
  }
}
void update(int k, int l, int r, Xyz xyz) {
  if (node[k].l == l && node[k].r == r) {
    node[k].ms = max(node[k].ms, xyz.x);
    node[k].ma = max(node[k].ma, xyz.y);
    node[k].sum += xyz.z;
  } else {
    int mid = (node[k].l + node[k].r) >> 1;
    if (r <= mid)
      update(k << 1, l, r, xyz);
    else if (l > mid)
      update((k << 1) ^ 1, l, r, xyz);
    else {
      update(k << 1, l, mid, xyz);
      update((k << 1) ^ 1, mid + 1, r, xyz);
    }
    up(k);
  }
}
Xyz read(int k, int l, int r) {
  Xyz ans;
  ans.x = ans.y = -2010000000;
  ans.z = 0;
  if (node[k].l == l && node[k].r == r)
    to_Xyz(ans, node[k]);
  else {
    int mid = (node[k].l + node[k].r) >> 1;
    Xyz tmp;
    if (r <= mid) {
      tmp = read(k << 1, l, r);
      to_Xyz(ans, tmp);
    } else if (l > mid) {
      tmp = read((k << 1) ^ 1, l, r);
      to_Xyz(ans, tmp);
    } else {
      tmp = read(k << 1, l, mid);
      to_Xyz(ans, tmp);
      tmp = read((k << 1) ^ 1, mid + 1, r);
      to_Xyz(ans, tmp);
    }
  }
  return ans;
}
int main() {
  int x, y, l, r;
  while (cin >> n >> lim) {
    for (int i = 1; i <= n; i++) {
      cin >> mbr[i].val;
      mbr[i].id = i;
    }
    for (int i = 1; i <= n; i++) cin >> mbr[i].age;
    sort(mbr + 1, mbr + n + 1, cmp1);
    mbr[0].age = -2010000000;
    mbr[n + 1].age = 2010000000;
    mbr[0].val = -2010000000;
    for (int i = 1; i <= n; i++) pos[mbr[i].id] = i;
    int tmp = 1;
    for (int i = 1; i <= n; i++) {
      while (mbr[i].age - lim > mbr[tmp].age) tmp++;
      ll[i] = tmp;
    }
    tmp = n;
    for (int i = n; i > 0; i--) {
      while (mbr[i].age + lim < mbr[tmp].age) tmp--;
      rr[i] = tmp;
    }
    ll[0] = rr[0] = 0;
    ll[n + 1] = rr[n + 1] = n + 1;
    cin >> q;
    for (int i = 1; i <= q; i++) {
      cin >> x >> y;
      x = pos[x];
      y = pos[y];
      if (x > y) swap(x, y);
      r = (upper_bound(ll, ll + n + 2, x) - ll) - 1;
      l = lower_bound(rr, rr + n + 2, y) - rr;
      query[i].x = l;
      query[i].y = r;
      query[i].id = i;
      query[i].mr = max(mbr[x].val, mbr[y].val);
      query[i].out = -2010000000;
    }
    build(1, 1, n);
    for (int i = 1; i <= n; i++) mbr[i].id = i;
    sort(mbr + 1, mbr + n + 1, cmp2);
    int next, now = 1;
    while (now <= n) {
      Xyz tmp;
      tmp.x = tmp.y = -2010000000;
      tmp.z = 1;
      int next = now;
      while (next <= n && mbr[next].val == mbr[now].val) next++;
      for (int i = now; i < next; i++) update(1, mbr[i].id, mbr[i].id, tmp);
      for (int i = now; i < next; i++) {
        tmp = read(1, ll[mbr[i].id], rr[mbr[i].id]);
        size[mbr[i].id] = tmp.z;
      }
      now = next;
    }
    sort(query + 1, query + q + 1, cmp3);
    int pt = q;
    now = n;
    while (now) {
      Xyz tmp;
      next = now;
      while (next && mbr[next].val == mbr[now].val) next--;
      while (pt && query[pt].mr > mbr[now].val) {
        query[pt].out = (query[pt].x <= query[pt].y)
                            ? read(1, query[pt].x, query[pt].y).x
                            : -2010000000;
        pt--;
      }
      for (int i = now; i > next; i--) {
        tmp.x = size[mbr[i].id];
        tmp.y = -2010000000;
        tmp.z = 0;
        update(1, mbr[i].id, mbr[i].id, tmp);
      }
      now = next;
    }
    while (pt) {
      query[pt].out = (query[pt].x <= query[pt].y)
                          ? read(1, query[pt].x, query[pt].y).x
                          : -2010000000;
      pt--;
    }
    sort(query + 1, query + q + 1, cmp4);
    for (int i = 1; i <= q; i++)
      cout << (query[i].out > -2010000000 ? query[i].out : -1) << endl;
  }
  return 0;
}
