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;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long expo(long long base, long long pow) {
  long long ans = 1;
  while (pow != 0) {
    if (pow & 1 == 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base *= base;
    base %= mod;
    pow /= 2;
  }
  return ans;
}
long long inv(long long x) { return expo(x, mod - 2); }
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int M = 1e5 + 5;
vector<int> vec[M];
int par_original[M], level[M], ancestor[M][21], euler[M], whichNodeAtIndex[M];
int n;
int dexx = 1;
int segTree[2][4 * M];
int LARGE, SMALL;
void dfs(int u, int p, int lev, bool is_root) {
  euler[u] = dexx;
  whichNodeAtIndex[dexx] = u;
  dexx++;
  if (is_root) {
    lev = 0;
    p = -1;
  }
  level[u] = lev;
  par_original[u] = p;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i];
    if (v == p) continue;
    dfs(v, u, lev + 1, 0);
  }
}
void preprocess() {
  memset(ancestor, -1, sizeof(ancestor));
  for (int i = 1; i <= n; i++) ancestor[i][0] = par_original[i];
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i <= n; i++) {
      if ((1 << j) > level[i]) continue;
      ancestor[i][j] = ancestor[ancestor[i][j - 1]][j - 1];
    }
  }
}
int LCA(int p, int q) {
  int a = level[p];
  int b = level[q];
  int lo;
  if (b > a) swap(p, q);
  for (lo = 0; (1 << lo) <= level[p]; lo++)
    ;
  lo--;
  for (int j = lo; j >= 0; j--) {
    if (level[p] - (1 << j) >= level[q]) {
      p = ancestor[p][j];
    }
  }
  if (p == q) return p;
  for (int j = lo; j >= 0; j--) {
    if ((ancestor[p][j] != -1) && (ancestor[p][j] != ancestor[q][j])) {
      p = ancestor[p][j];
      q = ancestor[q][j];
    }
  }
  return par_original[p];
}
void init(int root) {
  dfs(root, -1, 0, 1);
  preprocess();
}
void merge_node(int d, int node) {
  if (d == 0) {
    segTree[0][node] = min(segTree[0][2 * node], segTree[0][2 * node + 1]);
  } else {
    segTree[1][node] = max(segTree[1][2 * node], segTree[1][2 * node + 1]);
  }
}
void build(int node, int l, int r) {
  if (l > r) return;
  if (l == r) {
    segTree[0][node] = euler[l];
    segTree[1][node] = euler[l];
    return;
  }
  int mid = (l + r) / 2;
  build(2 * node, l, mid);
  build(2 * node + 1, mid + 1, r);
  for (int j = 0; j < 2; j++) {
    merge_node(j, node);
  }
}
int query(int node, int l, int r, int ql, int qr, int what) {
  if (l > r || l > qr || ql > qr || ql > r) {
    if (what == 0) {
      return LARGE;
    }
    return SMALL;
  }
  if (l >= ql && r <= qr) {
    return segTree[what][node];
  }
  int mid = (l + r) / 2;
  int a = query(2 * node, l, mid, ql, qr, what);
  int b = query(2 * node + 1, mid + 1, r, ql, qr, what);
  if (what == 0) return min(a, b);
  return max(a, b);
}
void update(int node, int l, int r, int pos, int val) {
  if (l > r || l > pos || pos > r) return;
  if (l >= pos && r <= pos) {
    segTree[0][node] = val;
    segTree[1][node] = val;
    return;
  }
  int mid = (l + r) / 2;
  update(2 * node, l, mid, pos, val);
  update(2 * node + 1, mid + 1, r, pos, val);
  for (int j = 0; j < 2; j++) {
    merge_node(j, node);
  }
}
int main() {
  scanf("%d", &(n));
  int q;
  scanf("%d", &(q));
  LARGE = n + 2;
  SMALL = -1;
  int u;
  for (int i = 2; i <= n; i++) {
    int v = i;
    scanf("%d", &(u));
    vec[u].push_back(v);
  }
  init(1);
  build(1, 1, n);
  while (q--) {
    int L, R;
    scanf("%d", &(L));
    scanf("%d", &(R));
    int minVal = query(1, 1, n, L, R, 0);
    int indexOfMin = whichNodeAtIndex[minVal];
    update(1, 1, n, indexOfMin, LARGE);
    int secondMinVal = query(1, 1, n, L, R, 0);
    int indexOfSecondMin = whichNodeAtIndex[secondMinVal];
    update(1, 1, n, indexOfMin, minVal);
    int maxVal = query(1, 1, n, L, R, 1);
    int indexOfMax = whichNodeAtIndex[maxVal];
    update(1, 1, n, indexOfMax, SMALL);
    int secondMaxVal = query(1, 1, n, L, R, 1);
    int indexOfSecondMax = whichNodeAtIndex[secondMaxVal];
    update(1, 1, n, indexOfMax, maxVal);
    int LCA_1 = LCA(indexOfMin, indexOfSecondMax);
    int LCA_1_depth = level[LCA_1];
    int LCA_2 = LCA(indexOfSecondMin, indexOfMax);
    int LCA_2_depth = level[LCA_2];
    int aps = max(LCA_1_depth, LCA_2_depth);
    if (LCA_1_depth > LCA_2_depth) {
      printf("%d %d\n", indexOfMax, aps);
    } else {
      printf("%d %d\n", indexOfMin, aps);
    }
  }
}