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;
struct Member {
  int respons, age, manage, id, rk;
  static bool by_respons(const Member &a, const Member &b) {
    return a.respons < b.respons;
  }
  static bool by_id(const Member &a, const Member &b) { return a.id < b.id; }
} member[100010];
struct Question {
  int x, y, id, maxr, minr, maxa, mina, ans;
  void input(int i) {
    id = i;
    cin >> x >> y;
    int ix = member[x].rk, iy = member[y].rk;
    minr = std::min(member[ix].respons, member[iy].respons);
    maxr = std::max(member[ix].respons, member[iy].respons);
    mina = std::min(member[ix].age, member[iy].age);
    maxa = std::max(member[ix].age, member[iy].age);
  }
  static bool by_maxr(const Question &a, const Question &b) {
    return a.maxr < b.maxr;
  }
  static bool by_id(const Question &a, const Question &b) {
    return a.id < b.id;
  }
} qustion[100010];
struct Discretize {
  int arr[100010], size;
  void discretize() {
    sort(arr + 1, arr + size + 1);
    size = unique(arr + 1, arr + size + 1) - arr - 1;
  }
  int get_GEq(int x) { return lower_bound(arr + 1, arr + size + 1, x) - arr; }
  int get_LEq(int x) {
    return upper_bound(arr + 1, arr + size + 1, x) - arr - 1;
  }
};
struct TreeArray : public Discretize {
  int c[100010], n;
  void init(int _n) {
    size = n = _n;
    for (int i = 1; i <= n; ++i) {
      c[i] = 0;
    }
  }
  void add(int x, int k) {
    x = get_GEq(x);
    for (; x <= n; x += (x & -x)) {
      c[x] += k;
    }
  }
  int sum(int x, int y) {
    x = get_GEq(x);
    y = get_LEq(y);
    return sum(y) - sum(x - 1);
  }

 private:
  int sum(int x) {
    int s = 0;
    for (; x; x -= (x & -x)) {
      s += c[x];
    }
    return s;
  }
};
struct TreeNode {
  int max, left, right;
};
struct SegTree : public Discretize {
  TreeNode node[100010 * 4];
  void init(int _n) {
    size = _n;
    create(1, _n);
  }
  void create(int left, int right, int root = 1) {
    node[root].left = left, node[root].right = right;
    node[root].max = -1;
    if (left < right) {
      create(left, (left + right) / 2, (root * 2));
      create((left + right) / 2 + 1, right, (root * 2 + 1));
    }
  }
  void insert(int pos, int k, int root = 1) { _insert(get_GEq(pos), k, root); }
  int get_max(int left, int right, int root = 1) {
    return _get_max(get_GEq(left), get_LEq(right), root);
  }

 private:
  void _insert(int pos, int k, int root) {
    if (node[root].left == node[root].right) {
      node[root].max = std::max(node[root].max, k);
      return;
    }
    if (pos <= node[(root * 2)].right) {
      _insert(pos, k, (root * 2));
    } else {
      _insert(pos, k, (root * 2 + 1));
    }
    node[root].max = max(node[(root * 2)].max, node[(root * 2 + 1)].max);
  }
  int _get_max(int left, int right, int root) {
    if (left > right || left > node[root].right || right < node[root].left) {
      return -1;
    }
    if (left <= node[root].left && node[root].right <= right) {
      return node[root].max;
    }
    return max(_get_max(left, right, (root * 2)),
               _get_max(left, right, (root * 2 + 1)));
  }
};
TreeArray age_cnt;
SegTree age_sum;
int main() {
  int n, k;
  while (cin >> n >> k) {
    age_cnt.init(n), age_sum.init(n);
    for (int i = 1; i <= n; ++i) {
      cin >> member[i].respons;
      member[i].id = i;
    }
    for (int i = 1; i <= n; ++i) {
      cin >> member[i].age;
      age_cnt.arr[i] = age_sum.arr[i] = member[i].age;
    }
    age_cnt.discretize(), age_sum.discretize();
    sort(member + 1, member + n + 1, Member::by_respons);
    for (int i = 1; i <= n; ++i) {
      member[member[i].id].rk = i;
    }
    for (int i = 1, p = 1; i <= n;) {
      while (p <= n && member[i].respons == member[p].respons) {
        age_cnt.add(member[p].age, 1);
        ++p;
      }
      while (i < p) {
        member[i].manage = age_cnt.sum(member[i].age - k, member[i].age + k);
        ++i;
      }
    }
    int m, x, y;
    cin >> m;
    for (int i = 1; i <= m; ++i) {
      qustion[i].input(i);
    }
    sort(qustion + 1, qustion + 1 + m, Question::by_maxr);
    for (int i = m, p = n; i; --i) {
      while (p && member[p].respons >= qustion[i].maxr) {
        age_sum.insert(member[p].age, member[p].manage);
        --p;
      }
      qustion[i].ans =
          age_sum.get_max(qustion[i].maxa - k, qustion[i].mina + k);
    }
    sort(qustion + 1, qustion + 1 + m, Question::by_id);
    for (int i = 1; i <= m; ++i) {
      cout << qustion[i].ans << endl;
    }
  }
  return 0;
}
