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>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
inline int read() {
  int num = 0;
  char c = ' ';
  int flag = 1;
  for (; c > '9' || c < '0'; c = getchar())
    if (c == '-') flag = -1;
  for (; c >= '0' && c <= '9';
       num = (num << 1) + (num << 3) + c - 48, c = getchar())
    ;
  return num * flag;
}
int n, k;
struct Node {
  int A, P, id;
  bool operator<(const Node b) const { return P < b.P; }
} a[100005];
int l[100005], r[100005], id[100005], v[100005];
inline void init_a() {
  for (register int i = (1); i <= (n); i++) v[i] = a[i].A;
  sort(v + 1, v + 1 + n);
  for (register int i = (1); i <= (n); i++)
    a[i].A = lower_bound(v + 1, v + 1 + n, a[i].A) - v;
}
int val[100005];
int sz = 0;
struct Banlance_Tree {
  int l, r, val, rd, sum, key;
} bst[100005 * 25];
struct Treap {
  int root;
  inline void update(int rt) {
    bst[rt].sum = max(bst[bst[rt].l].sum, max(bst[bst[rt].r].sum, bst[rt].key));
  }
  inline void insert(int &rt, int x, int key) {
    if (rt == 0) {
      rt = ++sz;
      bst[rt].val = x;
      bst[rt].key = bst[rt].sum = key;
      return;
    }
    if (bst[rt].val == x)
      bst[rt].key = max(key, bst[rt].key);
    else if (x < bst[rt].val)
      insert(bst[rt].l, x, key);
    else
      insert(bst[rt].r, x, key);
    update(rt);
  }
  inline int Get_rank(int rt, int x) {
    if (rt == 0) return -1;
    if (x == bst[rt].val)
      return max(bst[bst[rt].r].sum, bst[rt].key);
    else if (x > bst[rt].val)
      return Get_rank(bst[rt].r, x);
    else
      return max(bst[bst[rt].r].sum, max(bst[rt].key, Get_rank(bst[rt].l, x)));
  }
} tr[100005 * 4];
struct SEG {
  inline void build(int rt, int l, int r) {
    for (register int i = (l); i <= (r); i++)
      tr[rt].insert(tr[rt].root, a[i].A, val[i]);
    if (l == r) return;
    build(rt << 1, l, ((l + r) >> 1));
    build(rt << 1 | 1, ((l + r) >> 1) + 1, r);
  }
  inline int Get_rank(int rt, int l, int r, int x, int y, int k) {
    if (l == x && r == y) return tr[rt].Get_rank(tr[rt].root, k);
    if (y <= ((l + r) >> 1))
      return Get_rank(rt << 1, l, ((l + r) >> 1), x, y, k);
    else if (x > ((l + r) >> 1))
      return Get_rank(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y, k);
    else
      return max(Get_rank(rt << 1, l, ((l + r) >> 1), x, ((l + r) >> 1), k),
                 Get_rank(rt << 1 | 1, ((l + r) >> 1) + 1, r,
                          ((l + r) >> 1) + 1, y, k));
  }
} seg;
struct Charman_tree {
  int ls, rs, num;
} t[100005 * 25];
inline int pushup(int k) {
  t[k].num = t[t[k].ls].num + t[t[k].rs].num;
  return k;
}
int root[100005], tot = 0;
inline int build(int l, int r) {
  int mid = (l + r) >> 1, k = ++tot;
  if (l == r) {
    t[k].num = 0;
    return 0;
  }
  t[k].ls = build(l, mid);
  t[k].rs = build(mid + 1, r);
  return k;
}
inline int insert(int now, int l, int r, int pos) {
  int k = ++tot, mid = (l + r) >> 1;
  t[k] = t[now];
  if (l == r) {
    t[k].num++;
    return k;
  }
  if (pos <= mid)
    t[k].ls = insert(t[now].ls, l, mid, pos);
  else
    t[k].rs = insert(t[now].rs, mid + 1, r, pos);
  return pushup(k);
}
int query(int p, int q, int l, int r, int k) {
  if (l == r) return l;
  int mid = (l + r) >> 1, lnum = t[t[p].ls].num - t[t[q].ls].num;
  if (k <= lnum)
    return query(t[p].ls, t[q].ls, l, mid, k);
  else
    return query(t[p].rs, t[q].rs, mid + 1, r, k - lnum);
}
signed main() {
  memset(bst, 0, sizeof(bst));
  sz = 0;
  memset(tr, 0, sizeof(tr));
  memset(a, 0, sizeof(a));
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(v, 0, sizeof(v));
  memset(root, 0, sizeof(root));
  tot = 0;
  n = read(), k = read();
  for (register int i = (1); i <= (n); i++) a[i].A = read(), a[i].id = i;
  for (register int i = (1); i <= (n); i++) a[i].P = read();
  sort(a + 1, a + 1 + n);
  init_a();
  for (register int i = (1); i <= (n); i++) id[a[i].id] = i;
  root[0] = build(1, n);
  for (register int i = (1); i <= (n); i++)
    root[i] = insert(root[i - 1], 1, n, a[i].A);
  for (register int i = (1); i <= (n); i++) {
    Node tmp1 = a[i], tmp2 = a[i];
    tmp1.P = a[i].P - k, tmp2.P = a[i].P + k;
    l[i] = lower_bound(a + 1, a + 1 + n, tmp1) - a;
    r[i] = upper_bound(a + 1, a + 1 + n, tmp2) - a - 1;
  }
  for (register int i = (1); i <= (n); i++) {
    int posr = r[i], posl = l[i];
    int l = 1, r = (posr - posl + 1);
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (query(root[posr], root[posl - 1], 1, n, mid) <= a[i].A) {
        l = mid + 1;
        val[i] = mid;
      } else {
        r = mid - 1;
      }
    }
  }
  seg.build(1, 1, n);
  int Qnum = read();
  while (Qnum--) {
    int x = id[read()];
    int y = id[read()];
    if (a[x].A < a[y].A) swap(x, y);
    int posl = max(l[x], l[y]), posr = min(r[x], r[y]);
    if (posr < posl) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", seg.Get_rank(1, 1, n, posl, posr, a[x].A));
  }
  return 0;
}
