A club wants to take its members camping. In order to organize the event better the club directors decided to partition the members into several groups. 

Club member i has a responsibility value ri and an age value ai. A group is a non-empty subset of club members with one member known as group leader. A group leader should be one of the most responsible members of the group (his responsibility value is not less than responsibility of any other group member) and his age absolute difference with any other group member should not exceed k. 

Some club members are friends and want to be in the same group. They also like their group to be as large as possible. Now you should write a program that answers a series of questions like "What's the largest size of a group containing club member x and club member y?". It's possible for x or y to be the group leader.

Input

The first line contains two integers n and k (2 ≤ n ≤ 105, 0 ≤ k ≤ 109) — the number of club members and the age restriction for one group. 

The next line contains integer numbers r1, r2, ..., rn (1 ≤ ri ≤ 109) separated by space: ri denotes the i-th club member's responsibility. In the same way there are integers a1, a2, ..., an (1 ≤ ai ≤ 109) in the third line: ai denotes the i-th club member's age.

The next line contains an integer q denoting the number of questions that you should answer (1 ≤ q ≤ 105). The next q lines describe the questions. Each line contains two space-separated integers xi and yi (1 ≤ xi, yi ≤ n, xi ≠ yi) — the indices of the club members that should end up in the same group. 

Output

For each question print the maximum size of the group in a line. If making such a group is impossible print -1 instead.

Examples

Input

5 1
1 5 4 1 2
4 4 3 2 2
4
5 3
2 3
2 5
4 1


Output

4
3
-1
4

Note

In the first query the largest group with members 3 and 5 is {1, 3, 4, 5} where member 3 is the leader.

In the second query member 2 should be the leader so the group will be {1, 2, 3}.

In the third query the leader of the group should have age 3 so the only leader can be member 3, who is less responsible than member 2. So making a group is impossible.

The group for the fourth query is the same as first query.
#include <bits/stdc++.h>
using namespace std;
int a[100005], r[100005], b[100005], c[100005], q[100005], ans[100005];
int n, k, w, mm, v[100005], sa[100005], p[100005], t[100005 * 8];
struct side {
  int x, y, r, id;
  bool operator<(const side &o) const { return r > o.r; }
} e[100005];
void chg(int x, int d) {
  for (; x <= n; x += x & (-x)) c[x] += d;
}
int ask(int x) {
  int s = 0;
  for (; x; x -= x & (-x)) s += c[x];
  return s;
}
bool cmp(int a, int b) { return r[a] < r[b]; }
void Init() {
  int le, ri, t;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", r + i);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    v[i] = a[i];
  }
  sort(v + 1, v + 1 + n);
  for (int i = 1; i <= n; ++i) b[i] = lower_bound(v + 1, v + 1 + n, a[i]) - v;
  for (int i = 1; i <= n; ++i) sa[i] = i;
  sort(sa + 1, sa + 1 + n, cmp);
  for (int i = 1; i <= n; ++i) {
    t = 0;
    while (i < n && r[sa[i + 1]] == r[sa[i]]) {
      q[++t] = sa[i];
      ++i;
    }
    q[++t] = sa[i];
    for (int j = 1; j <= t; ++j) chg(b[q[j]], 1);
    for (int j = 1; j <= t; ++j) {
      le = lower_bound(v + 1, v + 1 + n, a[q[j]] - k) - v;
      ri = upper_bound(v + 1, v + 1 + n, a[q[j]] + k) - v - 1;
      p[q[j]] = ask(ri) - ask(le - 1);
    }
  }
  int h = 0;
  for (; (n + 1) >> h; ++h)
    ;
  mm = 1 << h;
}
int query(int l, int r) {
  l += mm - 1;
  r += mm + 1;
  int s = -2147483640;
  for (; l != r - 1; l >>= 1, r >>= 1) {
    if ((l & 1) == 0) s = ((s) > (t[l + 1]) ? (s) : (t[l + 1]));
    if ((r & 1) == 1) s = ((s) > (t[r - 1]) ? (s) : (t[r - 1]));
  }
  return s;
}
void modify(int x, int d) {
  x += mm;
  t[x] = ((t[x]) > (d) ? (t[x]) : (d));
  for (x >>= 1; x; x >>= 1)
    t[x] = ((t[x + x]) > (t[x + x + 1]) ? (t[x + x]) : (t[x + x + 1]));
}
void Work() {
  int m, x, y, le, ri;
  for (int i = 1; i <= 2 * mm; ++i) t[i] = -1;
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    ans[i] = -1;
    scanf("%d%d", &x, &y);
    if (r[x] >= r[y] &&
        ((a[x] - a[y]) > 0 ? (a[x] - a[y]) : (-(a[x] - a[y]))) <= k)
      ans[i] = ((ans[i]) > (p[x]) ? (ans[i]) : (p[x]));
    if (r[y] >= r[x] &&
        ((a[x] - a[y]) > 0 ? (a[x] - a[y]) : (-(a[x] - a[y]))) <= k)
      ans[i] = ((ans[i]) > (p[y]) ? (ans[i]) : (p[y]));
    le = ((a[x] - k) > (a[y] - k) ? (a[x] - k) : (a[y] - k));
    ri = ((a[y] + k) < (a[x] + k) ? (a[y] + k) : (a[x] + k));
    if (le <= ri) {
      le = lower_bound(v + 1, v + 1 + n, le) - v;
      ri = upper_bound(v + 1, v + 1 + n, ri) - v - 1;
      e[++w].x = le;
      e[w].y = ri;
      e[w].r = ((r[x]) > (r[y]) ? (r[x]) : (r[y]));
      e[w].id = i;
    }
  }
  sort(e + 1, e + 1 + w);
  int pos = n;
  for (int i = 1; i <= w; ++i) {
    while (pos && r[sa[pos]] >= e[i].r) {
      modify(b[sa[pos]], p[sa[pos]]);
      --pos;
    }
    int tmp = query(e[i].x, e[i].y);
    ans[e[i].id] = ((ans[e[i].id]) > (tmp) ? (ans[e[i].id]) : (tmp));
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
int main() {
  Init();
  Work();
  return 0;
}
