Problem: The company X has n employees numbered from 1 through n. Each employee u has a direct boss p_u (1 ≤ p_u ≤ n), except for the employee 1 who has no boss. It is guaranteed, that values p_i form a tree. Employee u is said to be in charge of employee v if u is the direct boss of v or there is an employee w such that w is in charge of v and u is the direct boss of w. Also, any employee is considered to be in charge of himself.

In addition, for each employee u we define it's level lv(u) as follow: 

  * lv(1)=0 
  * lv(u)=lv(p_u)+1 for u ≠ 1 



In the near future, there are q possible plans for the company to operate. The i-th plan consists of two integers l_i and r_i, meaning that all the employees in the range [l_i, r_i], and only they, are involved in this plan. To operate the plan smoothly, there must be a project manager who is an employee in charge of all the involved employees. To be precise, if an employee u is chosen as the project manager for the i-th plan then for every employee v ∈ [l_i, r_i], u must be in charge of v. Note, that u is not necessary in the range [l_i, r_i]. Also, u is always chosen in such a way that lv(u) is as large as possible (the higher the level is, the lower the salary that the company has to pay the employee).

Before any plan is operated, the company has JATC take a look at their plans. After a glance, he tells the company that for every plan, it's possible to reduce the number of the involved employees exactly by one without affecting the plan. Being greedy, the company asks JATC which employee they should kick out of the plan so that the level of the project manager required is as large as possible. JATC has already figured out the answer and challenges you to do the same.

Input

The first line contains two integers n and q (2 ≤ n ≤ 100 000, 1 ≤ q ≤ 100 000) — the number of employees and the number of plans, respectively.

The second line contains n-1 integers p_2, p_3, ..., p_n (1 ≤ p_i ≤ n) meaning p_i is the direct boss of employee i.

It is guaranteed, that values p_i form a directed tree with the root of 1.

Each of the following q lines contains two integers l_i and r_i (1 ≤ l_i<r_i ≤ n) — the range of the employees, involved in the corresponding plan.

Output

Print q lines, each containing two integers — the number of the employee which should be kicked from the corresponding plan and the maximum possible level of the project manager in that case.

If there are more than one way to choose that employee, print any of them.

Example

Input

11 5
1 1 3 3 3 4 2 7 7 6
4 6
4 8
1 11
9 11
8 11


Output

4 1
8 1
1 0
11 3
8 1

Note

In the example: 

<image> In the first query, we can choose whether 4 or 5 or 6 and the project manager will be 3.

In the second query, if we choose any employee other than the employee 8, the project manager will be 1. If we choose 8, the project manager will be 3. Since lv(3)=1 > lv(1)=0, choosing 8 is the best strategy.

In the third query, no matter how we choose the employee, the project manager will always be 1.

In the fourth query, if we choose 9 or 10 then the project manager will be 3. If we choose 11 then the project manager will be 7. Since lv(7)=3>lv(3)=1, we choose 11 as the answer.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main {
    static class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in)); // initial size buffer C = 32768 ??? /// default C = 8192
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            if (!tokin.hasMoreTokens()) {
                tokin = new StringTokenizer(in.readLine());
            }
            return tokin.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }

    static class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    static class pair {
        int val, ind;

        pair(int val1, int ind1) {
            val = val1;
            ind = ind1;
        }
    }

    static class SegmentTree {
        pair a[], element;
        int size, k2;

        SegmentTree(int n, pair b[]) {
            k2 = 1;
            size = n;
            while (k2 < n)
                k2 *= 2;
            k2 *= 2;
            a = new pair[k2];
            int ind = k2 / 2 - 1;
            for (int i = 0; i < size; i++) {
                a[ind + i] = b[i];
            }
        }

        // [0] [1 2] [3 4 5 6] [7 8 9 10 11 12 13 14]

        void makeMin() {
            element = new pair(Integer.MAX_VALUE, -1);
            for (int i = k2 / 2 - 1; i < k2; i++) {
                if (a[i] == null)
                    a[i] = element;
            }
            for (int i = k2 / 4 - 1; i >= 0; i = (i + 1) / 2 - 1) {
                for (int j = i; j <= i * 2; j++) {
                    a[j] = a[j * 2 + 1];
                    if (a[j * 2 + 2].val < a[j].val)
                        a[j] = a[j * 2 + 2];
                }
            }
        }

        void makeMax() {
            element = new pair(Integer.MIN_VALUE, -1);
            for (int i = k2 / 2 - 1; i < k2; i++) {
                if (a[i] == null)
                    a[i] = element;
            }
            for (int i = k2 / 4 - 1; i >= 0; i = (i + 1) / 2 - 1) {
                for (int j = i; j <= i * 2; j++) {
                    a[j] = a[j * 2 + 1];
                    if (a[j * 2 + 2].val > a[j].val)
                        a[j] = a[j * 2 + 2];
                }
            }
        }

        pair min(int l, int r) {
            return mini(0, 0, a.length / 2 - 1, l, r);
        }

        pair mini(int v, int tl, int tr, int l, int r) {
            if (l > r)
                return element;
            if (l == tl && r == tr)
                return a[v];
            int tm = (tl + tr) / 2;
            pair lp = mini(v * 2 + 1, tl, tm, l, Math.min(r, tm));
            pair rp = mini(v * 2 + 2, tm + 1, tr, Math.max(l, tm + 1), r);
            if (rp.val > lp.val) {
                return lp;
            } else {
                return rp;
            }
        }

        pair max(int l, int r) {
            return maxi(0, 0, a.length / 2 - 1, l, r);
        }

        pair maxi(int v, int tl, int tr, int l, int r) {
            if (l > r)
                return element;
            if (l == tl && r == tr)
                return a[v];
            int tm = (tl + tr) / 2;
            pair lp = maxi(v * 2 + 1, tl, tm, l, Math.min(r, tm));
            pair rp = maxi(v * 2 + 2, tm + 1, tr, Math.max(l, tm + 1), r);
            if (rp.val > lp.val) {
                return rp;
            } else {
                return lp;
            }
        }
    }

    static ArrayList<Integer> g[];

    static class lca {
        int h[], first[], order[], count = 0;
        ArrayList<Integer> g[];
        SegmentTree tlca;

        SegmentTree minfirst;
        SegmentTree maxfirst;

        lca(int n, ArrayList<Integer> g1[]) {
            g = g1;
            order = new int[n * 2 - 1];
            h = new int[n];
            first = new int[n];
            for (int i = 0; i < n; i++) {
                first[i] = -1;
            }
            dfs(0, 0);
            pair orderVert[] = new pair[order.length];
            for (int i = 0; i < order.length; i++) {
                orderVert[i] = new pair(h[order[i]], order[i]);
            }
            tlca = new SegmentTree(order.length, orderVert);
            tlca.makeMin();
            pair first1[] = new pair[first.length];
            for (int v = 0; v < first1.length; v++) {
                first1[v] = new pair(first[v], v);
            }
            minfirst = new SegmentTree(first.length, first1);
            minfirst.makeMin();
            maxfirst = new SegmentTree(first.length, first1);
            maxfirst.makeMax();
        }

        void dfs(int v, int h1) {
            order[count++] = v;
            h[v] = h1;
            if (first[v] == -1)
                first[v] = count - 1;
            for (int i = 0; i < g[v].size(); i++) {
                dfs(g[v].get(i), h1 + 1);
                order[count++] = v;
            }
        }

        pair getlca(int v1, int v2) {
            v1 = first[v1];
            v2 = first[v2];
            return tlca.min(Math.min(v1, v2), Math.max(v1, v2));
        }

        int minf(int v1, int v2) {
            int l = Math.min(v1, v2);
            int r = Math.max(v1, v2);
            return minfirst.min(l, r).ind;
        }

        int maxf(int v1, int v2) {
            int l = Math.min(v1, v2);
            int r = Math.max(v1, v2);
            return maxfirst.max(l, r).ind;
        }

        pair getLcaSegm(int v1, int v2) {
            int l1 = Math.min(v1, v2);
            int r1 = Math.max(v1, v2);
            int l = minf(l1, r1);
            int r = maxf(l1, r1);
            return tlca.min(first[l], first[r]);
        }
    }

    public static void main(String args[]) throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        int n = in.nextInt();
        int q = in.nextInt();
        g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
        }
        for (int i = 1; i < n; i++) {
            g[in.nextInt() - 1].add(i);
        }
        lca h = new lca(n, g);
        for (int i = 0; i < q; i++) {
            int v1 = in.nextInt() - 1;
            int v2 = in.nextInt() - 1;
            int t1 = h.minf(v1, v2);
            int t2 = h.maxf(v1, v2);
            int l = Math.min(v1, v2);
            int r = Math.max(v1, v2);
            int u1, u2;
            if (l == t1) {
                u1 = u2 = h.getLcaSegm(l + 1, r).ind;
            } else {
                if (r == t1) {
                    u1 = u2 = h.getLcaSegm(l, r - 1).ind;
                } else {
                    u1 = h.getLcaSegm(l, t1 - 1).ind;
                    u2 = h.getLcaSegm(t1 + 1, r).ind;
                }
            }
            pair p1 = h.getlca(u1, u2);
            int u3, u4;
            if (r == t2) {
                u3 = u4 = h.getLcaSegm(l, r - 1).ind;
            } else {
                if (l == t2) {
                    u3 = u4 = h.getLcaSegm(l + 1, r).ind;
                } else {
                    u3 = h.getLcaSegm(l, t2 - 1).ind;
                    u4 = h.getLcaSegm(t2 + 1, r).ind;
                }
            }
            pair p2 = h.getlca(u3, u4);
            if (p1.val < p2.val) {
                out.print((t2 + 1) + " " + p2.val + "\n");
            } else {
                out.print((t1 + 1) + " " + p1.val + "\n");
            }
            //out.print(h.getlca(v1, v2) + "\n");
        }
        out.close();
    }
}