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 x1062E
   {
   	static int[] p;
   	static int[] depth;
   	static int[][] anc;
   	static int[] amt;
   	static LinkedList<Integer>[] edges;
   	static LinkedList<Integer> revOrder;
   	public static void main(String[] hi) throws IOException 
      {
   		BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
   		int N = Integer.parseInt(st.nextToken());
   		int Q = Integer.parseInt(st.nextToken());
         int n = N; //lol;
   		p = new int[n+1];
   		amt = new int[n+1];
   		depth = new int[n+1];
   		Arrays.fill(p, -1);
   		p[0] = p[1] = 0;
   		anc = new int[n+1][17];
   		edges = new LinkedList[n+1];
   		revOrder = new LinkedList<Integer>();
   		for(int i = 0; i < edges.length; i++)
   			edges[i] = new LinkedList<Integer>();
         st = new StringTokenizer(infile.readLine());
   		for(int a = 2; a <= n; a++) 
         {
   			int p = Integer.parseInt(st.nextToken());
   			edges[a].add(p);
   			edges[p].add(a);
   		}
   		bfs();
   		genLCA();
   		//problem here
         int[] time = new int[N+1];
         ct = 0;
         dfs(1, time);
         maxq = new MaxTree(1, N);
         minq = new MinTree(1, N);
         for(int i=1; i <= N; i++)
         {
            maxq.update(i, time[i]);
            minq.update(i, time[i]);
         }
         StringBuilder sb = new StringBuilder();
         while(Q-->0)
         {
            st = new StringTokenizer(infile.readLine());
            int L = Integer.parseInt(st.nextToken());
            int R = Integer.parseInt(st.nextToken());
            if(L == R-1)
            {
               if(depth[L] < depth[R])
                  sb.append(L+" "+depth[R]+"\n");
               else
                  sb.append(R+" "+depth[L]+"\n");
               continue;
            }
            //min time node
            int A = getMin(L, R);
            //max time node
            int B = getMax(L, R);
            //lca time
            int res = 0;
            if(L == A)
               res = lca(getMin(L+1,R), B);
            else if(R == A)
               res = lca(getMin(L, R-1), B);
            else
            {
               int f1 = lca(getMin(L, A-1), getMax(L, A-1));
               int f2 = lca(getMin(A+1, R), getMax(A+1, R));
               res = lca(f1,f2);
            }
            int res2 = 0;
            if(L == B)
               res2 = lca(getMax(L+1,R), A);
            else if(R == B)
               res2 = lca(getMax(L, R-1), A);
            else
            {
               int f1 = lca(getMin(L, B-1), getMax(L, B-1));
               int f2 = lca(getMin(B+1, R), getMax(B+1, R));
               res2 = lca(f1,f2);
            }
            int best = Math.max(depth[res], depth[res2]);
            int lol = B;
            if(depth[res] == best)
               lol = A;
            sb.append(lol+" "+best+"\n");
         }
         System.out.print(sb);
   	}
      static MaxTree maxq;
      static MinTree minq;
      public static int getMin(int L, int R)
      {
         int val = minq.query(L,R);
         int low = L;
         int high = R;
         while(low != high)
         {
            int mid = (low+high)/2;
            if(val == minq.query(L, mid))
               high = mid;
            else
               low = mid+1;
         }return low;
      }
      public static int getMax(int L, int R)
      {
         int val = maxq.query(L,R);
         int low = L;
         int high = R;
         while(low != high)
         {
            int mid = (low+high)/2;
            if(val == maxq.query(L, mid))
               high = mid;
            else
               low = mid+1;
         }return low;
      }
      static int ct;
      public static void dfs(int curr, int[] time)
      {
         time[curr] = ct;
         for(int next: edges[curr])
            if(next != p[curr])
            {
               ct++;
               dfs(next, time);
            }
      }
      //lca shit
   	public static void compute() {
   		while(!revOrder.isEmpty()) {
   			int curr = revOrder.removeFirst();
   			amt[p[curr]] += amt[curr];
   		}
   	}
   	public static int lca(int a, int b) {
   		if(depth[a] > depth[b]) {
   			return lca(b, a);
   		}
   		if(depth[a] < depth[b]) {
   			b = getP(b, depth[a]);
   		}
   		for(int k = 16; k > 0; k--) {
   			while(anc[a][k] != anc[b][k]) {
   				a = anc[a][k];
   				b = anc[b][k];
   			}
   		}
   		while(a != b) {
   			a = p[a];
   			b = p[b];
   		}
   		return a;
   	}
   	public static int getP(int curr, int wantedD) {
   		for(int k = 16; depth[curr] != wantedD; k--) {
   			while(depth[curr] - (1<<k) >= wantedD) {
   				curr = anc[curr][k];
   			}
   		}
   		return curr;
   	}
   	public static void genLCA() {
   		for(int i = 1; i < p.length; i++) {
   			anc[i][0] = p[i];
   		}
   		for(int j = 1; j < anc[0].length; j++) {
   			for(int i = 1; i < p.length; i++) {
   				anc[i][j] = anc[anc[i][j-1]][j-1];
   			}
   		}
   	}
   	public static void bfs() {
   		LinkedList<Integer> q = new LinkedList<Integer>();
   		q.add(1);
   		while(!q.isEmpty()) {
   			int curr = q.removeFirst();
   			revOrder.addFirst(curr);
   			for(int child: edges[curr]) {
   				if(p[child] == -1) {
   					p[child] = curr;
   					depth[child] = 1 + depth[curr];
   					q.add(child);
   				}
   			}
   		}
   	}
   }
   class MinTree
   {
      //range query, non lazy
      final int[] val;
      final int treeFrom;
      final int length;
  
      public MinTree(int treeFrom, int treeTo) 
      {
         this.treeFrom = treeFrom;
         int length = treeTo - treeFrom + 1;
         int l;
         for (l = 0; (1 << l) < length; l++);
         val = new int[1 << (l + 1)];
         this.length = 1 << l;
      }
      public void update(int index, int delta) 
      {
         //replaces value
         int node = index - treeFrom + length;
         val[node] = delta;
         for (node >>= 1; node > 0; node >>= 1) 
           val[node] = comb(val[node << 1], val[(node << 1) + 1]);
      }
      public int query(int from, int to) 
      {
         //inclusive bounds
         if (to < from)
            return Integer.MAX_VALUE; //0 or 1?
         from += length - treeFrom;
         to += length - treeFrom + 1;
         //0 or 1?
         int res = Integer.MAX_VALUE;
         for (; from + (from & -from) <= to; from += from & -from) 
             res = comb(res, val[from / (from & -from)]);
         for (; to - (to & -to) >= from; to -= to & -to)
             res = comb(res, val[(to - (to & -to)) / (to & -to)]);
         return res;
      }
      public int comb(int a, int b)
      {
         //change this
         return Math.min(a,b);
      }
   }
   class MaxTree
   {
      //range query, non lazy
      final int[] val;
      final int treeFrom;
      final int length;
  
      public MaxTree(int treeFrom, int treeTo) 
      {
         this.treeFrom = treeFrom;
         int length = treeTo - treeFrom + 1;
         int l;
         for (l = 0; (1 << l) < length; l++);
         val = new int[1 << (l + 1)];
         this.length = 1 << l;
      }
      public void update(int index, int delta) 
      {
         //replaces value
         int node = index - treeFrom + length;
         val[node] = delta;
         for (node >>= 1; node > 0; node >>= 1) 
           val[node] = comb(val[node << 1], val[(node << 1) + 1]);
      }
      public int query(int from, int to) 
      {
         //inclusive bounds
         if (to < from)
            return 0; //0 or 1?
         from += length - treeFrom;
         to += length - treeFrom + 1;
         //0 or 1?
         int res = 0;
         for (; from + (from & -from) <= to; from += from & -from) 
             res = comb(res, val[from / (from & -from)]);
         for (; to - (to & -to) >= from; to -= to & -to)
             res = comb(res, val[(to - (to & -to)) / (to & -to)]);
         return res;
      }
      public int comb(int a, int b)
      {
         //change this
         return Math.max(a,b);
      }
   }