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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
char buf[100000], *p1, *p2;
int rd() {
  int x = 0;
  char s =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (s < '0' || s > '9')
    s = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++);
  while (s >= '0' && s <= '9')
    x = (((x << 2) + x) << 1) + s - '0',
    s = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++);
  return x;
}
namespace SA {
int n, ws[1050], wa[1050], wb[1050], rk[1050], height[1050], sa[1050];
char w[1050];
void build(int m) {
  int i, j, p, *x = wa, *y = wb;
  for (i = 1; i <= m; i++) ws[i] = 0;
  for (i = 1; i <= n; i++) ws[x[i] = w[i]]++;
  for (i = 1; i <= m; i++) ws[i] += ws[i - 1];
  for (i = n; i; i--) sa[ws[x[i]]--] = i;
  for (j = 1; j < n; j <<= 1) {
    for (p = 0, i = n; i > n - j; i--) y[++p] = i;
    for (i = 1; i <= n; i++)
      if (sa[i] > j) y[++p] = sa[i] - j;
    for (i = 1; i <= m; i++) ws[i] = 0;
    for (i = 1; i <= n; i++) ws[x[i]]++;
    for (i = 1; i <= m; i++) ws[i] += ws[i - 1];
    for (i = n; i; i--) sa[ws[x[y[i]]]--] = y[i];
    swap(x, y);
    m = 1;
    for (i = 1; i <= n; i++)
      x[sa[i]] = y[sa[i] + j] == y[sa[i + 1] + j] && y[sa[i]] == y[sa[i + 1]]
                     ? m
                     : m++;
    if (m > n) break;
  }
  for (i = 1; i <= n; i++) rk[sa[i]] = i;
  p = 0;
  for (i = 1; i <= n; i++)
    if (rk[i] != n) {
      j = rk[i] + 1;
      for (; w[i + p] == w[sa[j] + p]; p++)
        ;
      height[rk[i]] = p;
      if (p) p--;
    }
}
void init() {
  n = 6;
  w[1] = 'a';
  w[2] = 'b';
  w[3] = 'a';
  w[4] = 'b';
  w[5] = 'b';
  w[6] = 'a';
  build(128);
}
}  // namespace SA
namespace Scape_Goat_Tree {
int ch[1050][2], val[1050], siz[1050], tot[1050], ex[1050], S[1050], V[1050],
    tp, koishi;
int root, f[1050], cnt;
double AL = 0.75;
void pushup(int p) {
  siz[p] = siz[ch[p][0]] + siz[ch[p][0]] + ex[p];
  tot[p] = tot[ch[p][0]] + tot[ch[p][0]] + 1;
}
int GG(int p) { return tot[p] * AL < max(tot[ch[p][0]], tot[ch[p][0]]); }
int newnode(int v) {
  int p = ++cnt;
  siz[p] = tot[p] = ex[p] = 1;
  val[p] = v;
  return p;
}
void insert(int &p, int v, int fa) {
  if (!p) {
    p = newnode(v);
    f[p] = fa;
    return;
  }
  insert(ch[p][v > val[p]], v, p);
  pushup(p);
  if (GG(p)) koishi = p;
}
void init() {
  insert(root, 1, 0);
  insert(root, 2, 0);
  insert(root, 3, 0);
  insert(root, 4, 0);
  insert(root, 5, 0);
}
}  // namespace Scape_Goat_Tree
int n, head[100050], to[100050], nxt[100050], cnt, m;
int fa[100050], top[100050], son[100050], siz[100050], dep[100050], dfn[100050];
int f[20][100050], g[20][100050], Lg[100050];
int cmp1(int x, int y) {
  if (!x || !y) return x + y;
  return dfn[x] < dfn[y] ? x : y;
}
int cmp2(int x, int y) {
  if (!x || !y) return x + y;
  return dfn[x] > dfn[y] ? x : y;
}
inline void add(int u, int v) {
  to[++cnt] = v;
  nxt[cnt] = head[u];
  head[u] = cnt;
}
void df1(int x) {
  int i;
  siz[x] = 1;
  dfn[x] = ++dfn[0];
  for (i = head[x]; i; i = nxt[i]) {
    dep[to[i]] = dep[x] + 1;
    df1(to[i]);
    siz[x] += siz[to[i]];
    if (siz[to[i]] > siz[son[x]]) son[x] = to[i];
  }
}
void df2(int x, int t) {
  top[x] = t;
  if (son[x]) df2(son[x], t);
  int i;
  for (i = head[x]; i; i = nxt[i])
    if (to[i] != son[x]) df2(to[i], to[i]);
}
int lca(int x, int y) {
  if (!x || !y) return x + y;
  for (; top[x] != top[y]; y = fa[top[y]])
    if (dep[top[x]] > dep[top[y]]) swap(x, y);
  return dep[x] < dep[y] ? x : y;
}
int get_min(int l, int r) {
  if (l > r) return 0;
  int len = Lg[r - l + 1];
  return cmp1(f[len][l], f[len][r - (1 << len) + 1]);
}
int get_max(int l, int r) {
  if (l > r) return 0;
  int len = Lg[r - l + 1];
  return cmp2(g[len][l], g[len][r - (1 << len) + 1]);
}
int main() {
  Scape_Goat_Tree::init();
  SA::init();
  scanf("%d%d", &n, &m);
  int i, j;
  for (i = 2; i <= n; i++) {
    scanf("%d", &fa[i]);
    add(fa[i], i);
  }
  df1(1);
  df2(1, 1);
  Lg[0] = -1;
  for (i = 1; i <= n; i++) Lg[i] = Lg[i >> 1] + 1;
  for (i = 1; i <= n; i++) f[0][i] = g[0][i] = i;
  for (i = 1; (1 << i) <= n; i++) {
    for (j = 1; j <= n - (1 << i) + 1; j++) {
      f[i][j] = cmp1(f[i - 1][j], f[i - 1][j + (1 << (i - 1))]);
      g[i][j] = cmp2(g[i - 1][j], g[i - 1][j + (1 << (i - 1))]);
    }
  }
  while (m--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int x = get_min(l, r), y = get_max(l, r), ans1 = 0, ans2 = 0;
    int lx = get_min(l, x - 1), rx = get_min(x + 1, r);
    ans1 = lca(cmp1(lx, rx), y);
    int ly = get_max(l, y - 1), ry = get_max(y + 1, r);
    ans2 = lca(cmp2(ly, ry), x);
    if (dep[ans1] > dep[ans2]) {
      printf("%d %d\n", x, dep[ans1]);
    } else {
      printf("%d %d\n", y, dep[ans2]);
    }
  }
  return 0;
}