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.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeMap;

public class Main{
    int maxn = 100010;

    class SegTree {
        class node {
            int left, right;
            int val;

            node(int l, int r) {
                left = l;
                right = r;
                val = -1;
            }

            int mid() {
                return (left + right) >> 1;
            }
        }

        node tree[] = new node[maxn * 3];

        void init(int idx, int l, int r) {
            tree[idx] = new node(l, r);
            if (l == r)
                return;
            int mid = tree[idx].mid();
            init(idx << 1, l, mid);
            init(idx << 1 | 1, mid + 1, r);
        }

        void update(int idx, int pos, int v) {
            if (pos == tree[idx].left & pos == tree[idx].right) {
                if (v > tree[idx].val)
                    tree[idx].val = v;
                return;
            }
            int mid = tree[idx].mid();
            if (pos <= mid)
                update(idx << 1, pos, v);
            else
                update(idx << 1 | 1, pos, v);
            tree[idx].val = Math
                    .max(tree[idx << 1].val, tree[idx << 1 | 1].val);
        }

        int query(int idx, int l, int r) {
            if (tree[idx].left == l && tree[idx].right == r)
                return tree[idx].val;
            int mid = tree[idx].mid();
            if (r <= mid)
                return query(idx << 1, l, r);
            if (l > mid)
                return query(idx << 1 | 1, l, r);
            return Math.max(query(idx << 1, l, mid),
                    query(idx << 1 | 1, mid + 1, r));
        }
    }

    class Leader implements Comparable<Leader> {
        int age, cap, id;

        Leader(int i, int a, int c) {
            id = i;
            age = a;
            cap = c;
        }

        public int compareTo(Leader oth) {
            if (cap < oth.cap)
                return -1;
            return 1;
        }
    }

    class Query implements Comparable<Query> {
        int id;
        long left, right, cap, ans;

        Query(int i, int a, int b) {
            id = i;
            cap = Math.max(c[a], c[b]);
            if (age[a] > age[b]) {
                int temp = a;
                a = b;
                b = temp;
            }
            long temp = age[b] - age[a];
            if (temp > 2 * k) {
                ans = -1;
                //System.out.println(id + " -1");
                return;
            }
            if (temp <= k) {
                left = age[a] - (k - temp);
                right = age[b] + (k - temp);
            } else if (temp <= 2 * k) {
                left = age[b] - k;
                right = age[a] + k;
            }
//          System.out
//                  .println(age[a] + " " + age[b] + " " + left + " " + right);

        }

        public int compareTo(Query oth) {
            if (cap > oth.cap)
                return -1;
            return 1;
        }
    }

    class IndexedTree {
        int n, ss[] = new int[maxn];
        int b[] = new int[maxn];

        IndexedTree() {
            for (int i = 1; i < maxn; i++)
                b[i] = i & (-i);
        }

        void init(int n) {
            this.n = n;
            Arrays.fill(ss, 0);
        }

        void inc(int i, int k) {
            while (i <= n) {
                ss[i] += k;
                i += b[i];
            }
        }

        int get(int i) {
            int res = 0;
            while (i > 0) {
                res += ss[i];
                i -= b[i];
            }
            return res;
        }
    }

    StreamTokenizer in = new StreamTokenizer(new BufferedReader(
            new InputStreamReader(System.in)));

    long next() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    long age[] = new long[maxn], c[] = new long[maxn], k;
    SegTree st = new SegTree();
    IndexedTree it = new IndexedTree();
    Leader lead[] = new Leader[maxn];
    Query qq[] = new Query[maxn];
    TreeMap<Long, Integer> hashage = new TreeMap<Long, Integer>();
    TreeMap<Long, Integer> hashcap = new TreeMap<Long, Integer>();
    int n, m, cnt;

    void init() throws IOException {
        n = (int) next();
        k = next();
        for (int i = 1; i <= n; i++) {
            c[i] = next();
            hashcap.put(c[i], 0);
        }
        for (int i = 1; i <= n; i++) {
            age[i] = next();
            hashage.put(age[i], 0);
        }
        cnt = 0;
        Set<Long> set = hashcap.keySet();
        for (Long i : set)
            hashcap.put(i, ++cnt);
        cnt = 0;
        set = hashage.keySet();
        for (Long i : set)
            hashage.put(i, ++cnt);

        for (int i = 1; i <= n; i++)
            lead[i] = new Leader(i, hashage.get(age[i]), hashcap.get(c[i]));
        Arrays.sort(lead, 1, n + 1);
        m = (int) next();
        for (int i = 1; i <= m; i++)
            qq[i] = new Query(i, (int) next(), (int) next());
        Arrays.sort(qq, 1, m + 1);
    }

    int dp[] = new int[maxn];

    void work() {
        int i = 1;
        it.init(cnt);
        while (i <= n) {
            int j = i, temp = lead[j].cap;
            while (j <= n && lead[j].cap == temp)
                it.inc(lead[j++].age, 1);
            for (int p = i; p < j; p++) {
                int id = lead[p].id;
                int left = hashage.get(hashage.ceilingKey(age[id] - k));
                int right = hashage.get(hashage.floorKey(age[id] + k));
                dp[p] = it.get(right) - it.get(left - 1);
            }
            i = j;
        }
        st.init(1, 1, cnt);
        Arrays.fill(ans, -1);
    }

    int ans[] = new int[maxn];

    void query() {

        int ld = n;
        for (int i = 1; i <= m; i++) {
            int cap = hashcap.get(qq[i].cap);
            while (ld > 0 && lead[ld].cap >= cap)
                st.update(1, lead[ld].age, dp[ld--]);
            //System.out.println(qq[i].ans);
            if (qq[i].ans != -1) {
                int left, right = 0;
                if (hashage.containsKey(qq[i].left))
                    left = hashage.get(qq[i].left);
                else
                    left = hashage.get(hashage.ceilingKey(qq[i].left));
                if (qq[i].right < hashage.firstKey())
                    System.out.println(qq[i].id + " fuck");
                if (hashage.containsKey(qq[i].right))
                    right = hashage.get(qq[i].right);
                else
                    right = hashage.get(hashage.floorKey(qq[i].right));
                if (left <= right)
                    ans[qq[i].id] = st.query(1, left, right);
            }
        }
    }

    void run() throws IOException {
        init();
        work();
        query();
        for (int i = 1; i <= m; i++)
            System.out.println(ans[i]);
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}
