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;
class Coor {
 public:
  int x, y;
  const bool operator<(const Coor &b) const { return x < b.x; }
};
class Event {
 public:
  int x, y, val;
  Event() {}
  Event(int _x, int _y, int _val) : x(_x), y(_y), val(_val) {}
  const bool operator<(const Event &b) const { return x > b.x; }
};
class Query {
 public:
  int id, x, y1, y2, sol;
  Query() {}
  Query(int _id, int _x, int _y1, int _y2) : id(_id), x(_x), y1(_y1), y2(_y2) {}
  const bool operator<(const Query &b) const { return x > b.x; }
};
class Node1 {
 public:
  int vl, vr, sum;
  Node1 *_l, *_r;
  Node1(int _vl, int _vr) : vl(_vl), vr(_vr) {
    sum = 0;
    _l = _r = NULL;
  }
  Node1 *left() {
    int m = (vl + vr) >> 1;
    if (!_l) _l = new Node1(vl, m);
    return _l;
  }
  Node1 *right() {
    int m = (vl + vr) >> 1;
    if (!_r) _r = new Node1(m + 1, vr);
    return _r;
  }
  void insert(int x) {
    sum++;
    if (vl == vr) return;
    int m = (vl + vr) >> 1;
    if (x <= m)
      left()->insert(x);
    else
      right()->insert(x);
  }
  int query(int l, int r) {
    if (vl == l && vr == r) {
      return sum;
    } else {
      int m = (vl + vr) >> 1;
      if (r <= m)
        return left()->query(l, r);
      else if (l > m)
        return right()->query(l, r);
      else
        return left()->query(l, m) + right()->query(m + 1, r);
    }
  }
};
class Node2 {
 public:
  int vl, vr, mval;
  Node2 *_l, *_r;
  Node2(int _vl, int _vr) : vl(_vl), vr(_vr) {
    mval = -1;
    _l = _r = NULL;
  }
  Node2 *left() {
    int m = (vl + vr) >> 1;
    if (!_l) _l = new Node2(vl, m);
    return _l;
  }
  Node2 *right() {
    int m = (vl + vr) >> 1;
    if (!_r) _r = new Node2(m + 1, vr);
    return _r;
  }
  void insert(int x, int val) {
    if (val > mval) mval = val;
    if (vl == vr) return;
    int m = (vl + vr) >> 1;
    if (x <= m)
      left()->insert(x, val);
    else
      right()->insert(x, val);
  }
  int query(int l, int r) {
    if (vl == l && vr == r) {
      return mval;
    } else {
      int m = (vl + vr) >> 1;
      if (r <= m)
        return left()->query(l, r);
      else if (l > m)
        return right()->query(l, r);
      else
        return max(left()->query(l, m), right()->query(m + 1, r));
    }
  }
};
int n, d, ysz;
int yc[100050 * 3];
Coor pt[100050];
int sol[100050];
vector<Event> ev;
vector<Query> qu;
const int inf = 1000000001;
inline int get(int y) { return lower_bound(yc, yc + ysz, y) - yc; }
inline void solve() {
  ysz = 0;
  for (int i = 0; i < n; i++) {
    yc[ysz++] = pt[i].y;
    yc[ysz++] = pt[i].y + d;
    yc[ysz++] = pt[i].y - d;
  }
  sort(yc, yc + ysz);
  ysz = unique(yc, yc + ysz) - yc;
  sort(pt, pt + n);
  Node1 st1(0, ysz);
  int i, j;
  for (i = 0; i < n; i = j) {
    for (j = i; pt[j].x == pt[i].x; j++) st1.insert(get(pt[j].y));
    for (j = i; pt[j].x == pt[i].x; j++)
      ev.push_back(Event(pt[j].x, pt[j].y,
                         st1.query(get(pt[j].y - d), get(pt[j].y + d))));
  }
  sort(ev.begin(), ev.end());
  sort(qu.begin(), qu.end());
  int ei = 0;
  Node2 st2(0, ysz);
  for (int qi = 0; qi < qu.size(); qi++) {
    int x = qu[qi].x;
    int y1 = qu[qi].y1;
    int y2 = qu[qi].y2;
    if (y1 > y2) {
      qu[qi].sol = -1;
      continue;
    }
    while (ei < ev.size() && ev[ei].x >= x) {
      st2.insert(get(ev[ei].y), ev[ei].val);
      ei++;
    }
    qu[qi].sol = st2.query(get(y1), get(y2));
  }
  for (int i = 0; i < qu.size(); i++) sol[qu[i].id] = qu[i].sol;
}
int main(void) {
  scanf("%d %d", &n, &d);
  for (int i = 0; i < n; i++) scanf("%d", &pt[i].x);
  for (int i = 0; i < n; i++) scanf("%d", &pt[i].y);
  int qn;
  scanf("%d", &qn);
  for (int qi = 0; qi < qn; qi++) {
    int i1, i2;
    scanf("%d %d", &i1, &i2);
    i1--;
    i2--;
    if (pt[i1].y > pt[i2].y) swap(i1, i2);
    qu.push_back(
        Query(qi, max(pt[i1].x, pt[i2].x), pt[i2].y - d, pt[i1].y + d));
  }
  solve();
  for (int i = 0; i < qn; i++) printf("%d\n", sol[i]);
  return 0;
}
