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:
//package que_b;

import java.io.*;
import java.util.*;
import java.math.*;

public class utkarsh {

    InputStream is;
    PrintWriter out;
    
    long mod = (long) (1e9 + 7);
    int inf = (int)(1e9);
    
    ArrayList <Integer> a[];
    int in[], ot[], t = 0, bi[], bo[], dp[][], level[];
    
    class pair {
        int F, S, I;
        pair(int f, int s, int i) {
            F = f;  S = s; I = i;
        }
    }
    
    void dfs(int s) {
        t++;
        bi[t] = s;
        in[s] = t;
        for(int x : a[s]) {
            level[x] = level[s] + 1;
            dfs(x);
        }
        t++;
        bo[t] = s;
        ot[s] = t;
    }
    
    pair trin[], trot[];
    
    void buildin(int n, int s, int e) {
        if(s > e)   return;
        if(s == e) {
            trin[n] = new pair(in[s], inf, s);    return;
        }
        int m = (s + e) >> 1;
        int lc = n + 1 + n;
        int rc = lc + 1;
        buildin(lc, s, m);  buildin(rc, m+1, e);
        int i, ll, rr;
        if(trin[lc].F < trin[rc].F) {
            i = trin[lc].I;
            ll = trin[lc].F;
            if(trin[lc].S < trin[rc].F) {
                rr = trin[lc].S;
            } else {
                rr = trin[rc].F;
            }
        } else {
            i = trin[rc].I;
            ll = trin[rc].F;
            if(trin[rc].S < trin[lc].F) {
                rr = trin[rc].S;
            } else {
                rr = trin[lc].F;
            }
        }
        trin[n] = new pair(ll, rr, i);
    }
    
    void buildot(int n, int s, int e) {
        if(s > e)   return;
        if(s == e) {
            trot[n] = new pair(ot[s], -inf, s);    return;
        }
        int m = (s + e) >> 1;
        int lc = n + 1 + n;
        int rc = lc + 1;
        buildot(lc, s, m);  buildot(rc, m+1, e);
        int i, ll, rr;
        if(trot[lc].F > trot[rc].F) {
            i = trot[lc].I;
            ll = trot[lc].F;
            if(trot[lc].S > trot[rc].F) {
                rr = trot[lc].S;
            } else {
                rr = trot[rc].F;
            }
        } else {
            i = trot[rc].I;
            ll = trot[rc].F;
            if(trot[rc].S > trot[lc].F) {
                rr = trot[rc].S;
            } else {
                rr = trot[lc].F;
            }
        }
        trot[n] = new pair(ll, rr, i);
    }
    
    pair queryin(int n, int s, int e, int l, int r) {
        if(s > e || s > r || l > e) return new pair(inf, inf, 0);
        if(l <= s && e <= r)    return trin[n];
        int m = (s + e) >> 1;
        int lc = n + 1 + n;
        int rc = lc + 1;
        pair p = queryin(lc, s, m, l, r);
        pair q = queryin(rc, m+1, e, l, r);
        int i, ll, rr;
        if(p.F < q.F) {
            i = p.I;
            ll = p.F;
            if(p.S < q.F) {
                rr = p.S;
            } else {
                rr = q.F;
            }
        } else {
            i = q.I;
            ll = q.F;
            if(q.S < p.F) {
                rr = q.S;
            } else {
                rr = p.F;
            }
        }
        return new pair(ll, rr, i);
    }
    
    pair queryot(int n, int s, int e, int l, int r) {
        if(s > e || s > r || l > e) return new pair(-inf, -inf, 0);
        if(l <= s && e <= r)    return trot[n];
        int m = (s + e) >> 1;
        int lc = n + 1 + n;
        int rc = lc + 1;
        pair p = queryot(lc, s, m, l, r);
        pair q = queryot(rc, m+1, e, l, r);
        int i, ll, rr;
        if(p.F > q.F) {
            i = p.I;
            ll = p.F;
            if(p.S > q.F) {
                rr = p.S;
            } else {
                rr = q.F;
            }
        } else {
            i = q.I;
            ll = q.F;
            if(q.S > p.F) {
                rr = q.S;
            } else {
                rr = p.F;
            }
        }
        return new pair(ll, rr, i);
    }
    
    int lca(int u, int v) {
        if(level[u] > level[v]) {
            u ^= v; v ^= u; u ^= v;
        }
        int d = level[v] - level[u];
        for(int i = 19; i >= 0; i--) {
            if((d & (1 << i)) > 0)  v = dp[v][i];
        }
        if(u == v)  return u;
        for(int i = 19; i >= 0; i--) {
            if(dp[u][i] != dp[v][i]) {
                u = dp[u][i];   v = dp[v][i];
            }
        }
        return dp[u][0];
    }
    
    void solve() {
        int n = ni(), q = ni();
        a = new ArrayList[n];
        dp = new int[n][20];
        for(int i = 0; i < n; i++) {
            Arrays.fill(dp[i], -1);
            a[i] = new ArrayList<>();
        }
        for(int i = 1; i < n; i++) {
            int pt = ni()-1;
            dp[i][0] = pt;
            a[pt].add(i);
        }
        
        for(int j = 1; j < 20; j++) {
            for(int i = 0; i < n; i++) {
                if(dp[i][j-1] == -1)    continue;
                dp[i][j] = dp[ dp[i][j-1] ][j-1];
            }
        }
        bi = new int[n+n+1];
        bo = new int[n+n+1];
        level = new int[n];
        
        in = new int[n];
        ot = new int[n];
        dfs(0);
        trin = new pair[n << 2];
        trot = new pair[n << 2];
        buildin(0, 0, n-1);
        buildot(0, 0, n-1);
        while(q-- > 0) {
            int l = ni()-1, r = ni()-1;
            pair min = queryin(0, 0, n-1, l, r);
            pair mot = queryot(0, 0, n-1, l, r);
            if(min.I == mot.I) {
                int d = lca(bi[min.S], bo[mot.S]);
                out.println((min.I+1) +" "+ level[d]);
            } else {
                int d1 = lca(bi[min.F], bo[mot.S]);
                int l1 = level[d1];
                int d2 = lca(bi[min.S], bo[mot.F]);
                int l2 = level[d2];
                if(l1 > l2) {
                    out.println((mot.I+1) +" "+ l1);
                } else {
                    out.println((min.I+1) +" "+ l2);
                }
            }
        }
    }
    
    long mp(long b, long e) {
        long r = 1;
        while(e > 0) {
            if((e&1) == 1)  r = (r * b) % mod;
            b = (b * b) % mod;
            e >>= 1;
        }
        return r;
    }

    //---------- I/O Template ----------
    
    public static void main(String[] args) { new utkarsh().run(); }
    void run() { 
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }
    
    byte input[] = new byte[1024];
    int len = 0, ptr = 0;
    
    int readByte() { 
        if(ptr >= len) { ptr = 0; 
            try { len = is.read(input); } 
            catch(IOException e) { throw new InputMismatchException(); } 
            if(len <= 0) { return -1; } 
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() { 
        int b = readByte(); 
        while(b != -1 && isSpaceChar(b)) { b = readByte(); } 
        return b;
    }
    
    char nc() { return (char)skip(); }
    String ns() { 
        int b = skip(); 
        StringBuilder sb = new StringBuilder(); 
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } 
        return sb.toString();
    }
    String nLine() { 
        int b = skip(); 
        StringBuilder sb = new StringBuilder(); 
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } 
        return sb.toString();
    }
    int ni() { 
        int n = 0, b = readByte(); 
        boolean minus = false; 
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } 
        if(b == '-') { minus = true; b = readByte(); } 
        if(b == -1) { return -1; }  //no input 
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } 
        return minus ? -n : n;
    }
    long nl() { 
        long n = 0L;    int b = readByte(); 
        boolean minus = false; 
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } 
        if(b == '-') { minus = true; b = readByte(); } 
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } 
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) { 
        int a[] = new int[n]; 
        for(int i = 0; i < n; i++) { a[i] = ni(); } 
        return a;
    }
    char[] ns(int n) { 
        char c[] = new char[n]; 
        int i, b = skip(); 
        for(i = 0; i < n; i++) { 
            if(isSpaceChar(b)) { break; } 
            c[i] = (char)b; b = readByte(); 
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}