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.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
    void solve() {
        int n=ni(),q=ni();
        g=new ArrayList[n+1];
        for(int i=1;i<=n;i++) g[i]=new ArrayList<>();
        for(int i=1;i<n;i++){
            int p=ni();
            g[i+1].add(p); g[p].add(i+1);
        }
        MAXL=log2(n)+1;
        parent=new int[n+1];
        level=new int[n+1];
        in=new int[n+1];
        dfs(1,-1,0);
        precompute(n);
        tree1=new int[4*n+1];
        tree2MN=new int[4*n+1];
        tree2MX=new int[4*n+1];
        build(1,1,n);
        while(q-->0){
            int l=ni(),r=ni();
            int u=queryMN(1,l,r,1,n),v=queryMX(1,l,r,1,n);
            int l1=computeLCA(u,l,r,n),l2=computeLCA(v,l,r,n);
          //  pw.println(u+" "+v+" "+l1+" "+l2);
            if(level[l1]>level[l2]){
                pw.println(u+" "+level[l1]);

            }else pw.println(v+" "+level[l2]);
        }

    }
    ArrayList<Integer> g[];
    int P[][];
    int MAXL; ///MAXL=log2(n);
    int parent[];
    int level[];
    int in[];
    int cc=0;

    int tree1[],tree2MN[],tree2MX[];
    int computeLCA(int u,int l,int r,int n){
        if(u==l) return query1(1,l+1,r,1,n);
        if(u==r) return query1(1,l,r-1,1,n);
        return lca(query1(1,l,u-1,1,n),query1(1,u+1,r,1,n));
    }
    void build(int id,int l,int r){
        if(l==r){
            tree1[id]=l;
            tree2MN[id]=tree2MX[id]=l;
        }else {
            int mid=(l+r)>>1;
            build(2*id,l,mid);
            build(2*id+1,mid+1,r);
            tree1[id]=lca(tree1[2*id],tree1[2*id+1]);
            if(in[tree2MN[2*id]]<in[tree2MN[2*id+1]]){
                tree2MN[id]=tree2MN[2*id];
            }else tree2MN[id]=tree2MN[2*id+1];

            if(in[tree2MX[2*id]]>in[tree2MX[2*id+1]]){
                tree2MX[id]=tree2MX[2*id];
            }else tree2MX[id]=tree2MX[2*id+1];
        }
    }
    int query1(int id,int x,int y,int l,int r){

        if(r<x || l>y) return -1;
        if(x<=l && r<=y) return tree1[id];
        int mid=(l+r)>>1;
        int l1=query1(2*id,x,y,l,mid),l2=query1(2*id+1,x,y,mid+1,r);
        if(l1==-1) return l2;
        else if(l2==-1) return l1;

        return lca(l1,l2);
    }
    int queryMN(int id,int x,int y,int l,int r){
        if(r<x || l>y) return -1;
        if(x<=l && r<=y) return tree2MN[id];
        int mid=(l+r)>>1;
        int id1=queryMN(2*id,x,y,l,mid),id2=queryMN(2*id+1,x,y,mid+1,r);
        if(id1==-1) return id2;
        if(id2==-1) return id1;
        if(in[id1]<in[id2]) return id1;
        return id2;
    }
    int queryMX(int id,int x,int y,int l,int r){
        if(r<x || l>y) return -1;
        if(x<=l && r<=y) return tree2MX[id];
        int mid=(l+r)>>1;
        int id1=queryMX(2*id,x,y,l,mid),id2=queryMX(2*id+1,x,y,mid+1,r);
        if(id1==-1) return id2;
        if(id2==-1) return id1;
        if(in[id1]>in[id2]) return id1;
        return id2;
    }


    void dfs(int v,int pr,int l){
        parent[v]=pr;
        level[v]=l;
        in[v]=++cc;
        for(int u : g[v]){
            if(u!=pr){
                dfs(u,v,l+1);
            }
        }
    }

    void precompute(int n){
        P=new int[n+1][MAXL+1];

        for(int i=1;i<=n;i++){
            for(int j=0;(1<<j)<n;j++){
                P[i][j]=-1;
            }
        }
        for(int i=1;i<=n;i++)P[i][0]=parent[i];
        for(int j=1;(1<<j)<n;j++){
            for(int i=1;i<=n;i++){
                if(P[i][j-1]!=-1)P[i][j]=P[P[i][j-1]][j-1];
            }
        }

    }
    int log2(int v){
        return (int)(Math.log10(v)/Math.log10(2));
    }
    int lca(int u ,int v){
        if(level[u]<level[v]){
            int t=u;
            u=v;
            v=t;
        }
        int dist=level[u]-level[v];
        while(dist>0){
            int raise_by=log2(dist);
            u=P[u][raise_by];
            dist-=(1<<raise_by);
        }
        if(u==v) return u;
        for(int j=MAXL;j>=0;j--){
            if(P[u][j]!=-1 && P[u][j]!=P[v][j]){
                u=P[u][j];
                v=P[v][j];
            }
        }
        return parent[u];

    }

    long M =(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

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

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}