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;
int read() {
  char ch = getchar();
  int x = 0, op = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - 48;
  return x * op;
}
const int N = 1e5 + 5;
int n, m, x, y, fa[N], dep[N], siz[N], mx[N], top[N], cnt, head[N], in[N], clk;
struct edge {
  int to, nxt;
} e[N << 1];
struct node {
  int mx1, mx2, mi1, mi2;
  node() {}
  node(int mx1, int mx2, int mi1, int mi2)
      : mx1(mx1), mx2(mx2), mi1(mi1), mi2(mi2) {}
} t[N << 2];
void adde(int x, int y) {
  e[++cnt].to = y;
  e[cnt].nxt = head[x];
  head[x] = cnt;
}
void dfs(int u) {
  siz[u] = 1;
  mx[u] = 0;
  for (int i = head[u], v; i; i = e[i].nxt) {
    v = e[i].to;
    dep[v] = dep[u] + 1;
    dfs(v);
    siz[u] += siz[v];
    if (siz[v] > siz[mx[u]]) mx[u] = v;
  }
}
void dfs1(int u, int t) {
  top[u] = t;
  in[u] = ++clk;
  if (mx[u]) dfs1(mx[u], t);
  for (int i = head[u], v; i; i = e[i].nxt)
    if (v = e[i].to, v != mx[u]) dfs1(v, v);
}
int lca(int x, int y) {
  for (; top[x] != top[y]; x = fa[top[x]])
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
  return dep[x] < dep[y] ? x : y;
}
void Max(int &x, int &y, int v) {
  if (in[v] > in[x])
    y = x, x = v;
  else if (in[v] > in[y])
    y = v;
}
void Min(int &x, int &y, int v) {
  if (in[v] < in[x])
    y = x, x = v;
  else if (in[v] < in[y])
    y = v;
}
node merge(node x, node y) {
  int mx1 = 0, mx2 = 0, mi1 = n + 1, mi2 = n + 1;
  Max(mx1, mx2, x.mx1);
  Max(mx1, mx2, x.mx2);
  Max(mx1, mx2, y.mx1);
  Max(mx1, mx2, y.mx2);
  Min(mi1, mi2, x.mi1);
  Min(mi1, mi2, x.mi2);
  Min(mi1, mi2, y.mi1);
  Min(mi1, mi2, y.mi2);
  return node(mx1, mx2, mi1, mi2);
}
void build(int now, int l, int r) {
  if (l == r) {
    t[now] = node(l, 0, l, n + 1);
    return;
  }
  int mid = l + r >> 1;
  build((now << 1), l, mid);
  build((now << 1 | 1), mid + 1, r);
  t[now] = merge(t[(now << 1)], t[(now << 1 | 1)]);
}
node qry(int now, int l, int r, int x, int y) {
  if (x == l && r == y) return t[now];
  int mid = l + r >> 1;
  if (y <= mid)
    return qry((now << 1), l, mid, x, y);
  else if (x > mid)
    return qry((now << 1 | 1), mid + 1, r, x, y);
  else
    return merge(qry((now << 1), l, mid, x, mid),
                 qry((now << 1 | 1), mid + 1, r, mid + 1, y));
}
int main() {
  n = read(), m = read();
  for (int i = (2); i <= (n); i++) fa[i] = read(), adde(fa[i], i);
  dfs(1);
  dfs1(1, 1);
  in[0] = 0, dep[0] = -1, in[n + 1] = n + 1;
  build(1, 1, n);
  while (m--) {
    x = read(), y = read();
    node t = qry(1, 1, n, x, y);
    int p = 0, pp, tmp;
    if (tmp = lca(t.mx1, t.mi2), dep[tmp] > dep[p]) p = tmp, pp = t.mi1;
    if (tmp = lca(t.mx2, t.mi1), dep[tmp] > dep[p]) p = tmp, pp = t.mx1;
    printf("%d %d\n", pp, dep[p]);
  }
  return 0;
}