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 int INF = (int)1e9;
struct P {
  int first, second;
  P(){};
  P(int a, int b) { first = a, second = b; }
};
P min(P a, P b, int type) { return ((a.first < b.first) ^ type) ? a : b; }
int get(int a, int b, int type) { return ((a < b) ^ type) ? a : b; }
const int N = 100050;
const int LOG_N = 17;
int root = 0;
int n, q, a, b;
int mm[N];
int st[2][LOG_N][N];
int loc[2][N], id[2][N];
int tim[2] = {0, 0};
vector<int> G[N];
int parent[LOG_N][N];
int depth[N], par[N];
void dfs(int v, int p, int d) {
  id[0][tim[0]] = v;
  loc[0][v] = tim[0]++;
  parent[0][v] = p;
  depth[v] = d;
  for (int nxt : G[v]) {
    if (nxt != p) dfs(nxt, v, d + 1);
  }
  id[1][tim[1]] = v;
  loc[1][v] = tim[1]++;
}
void init(int V) {
  dfs(root, -1, 0);
  for (int k = 0; k + 1 < LOG_N; k++) {
    for (int v = 0; v < V; v++) {
      if (parent[k][v] < 0)
        parent[k + 1][v] = -1;
      else
        parent[k + 1][v] = parent[k][parent[k][v]];
    }
  }
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) {
    int tmp = u;
    u = v;
    v = tmp;
  }
  for (int k = 0; k < LOG_N; k++) {
    if ((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if (u == v) return u;
  for (int k = LOG_N - 1; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
void init_rmq() {
  for (int k = 0; k < 2; k++) {
    for (int i = 0; i < n; i++) {
      st[k][0][i] = loc[k][i];
    }
    for (int lg = 1; lg < LOG_N; lg++) {
      for (int j = 0; j + (1 << lg) - 1 < n; j++) {
        st[k][lg][j] =
            get(st[k][lg - 1][j], st[k][lg - 1][j + (1 << (lg - 1))], k);
      }
    }
  }
}
int rmq(int l, int r, int type) {
  if (l > r) return type == 0 ? INF : -INF;
  int k = mm[r - l + 1];
  return get(st[type][k][l], st[type][k][r - (1 << k) + 1], type);
}
P get_del(int l, int r, int del) {
  int left = min(rmq(l, del - 1, 0), rmq(del + 1, r, 0));
  int right = max(rmq(l, del - 1, 1), rmq(del + 1, r, 1));
  int ca = lca(id[0][left], id[1][right]);
  return P(depth[ca], del);
}
P get_res(int l, int r) {
  int mn = rmq(l, r, 0);
  mn = id[0][mn];
  P mn_res = get_del(l, r, mn);
  int mx = rmq(l, r, 1);
  mx = id[1][mx];
  P mx_res = get_del(l, r, mx);
  return min(mn_res, mx_res, 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  mm[0] = -1;
  for (int i = 1; i < N; i++)
    mm[i] = (i & (i - 1)) == 0 ? mm[i - 1] + 1 : mm[i - 1];
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    cin >> a;
    a--;
    G[a].push_back(i);
  }
  init(n);
  init_rmq();
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    auto res = get_res(l, r);
    cout << res.second + 1 << " " << res.first << endl;
  }
}