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>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long gcd(long long a, long long b) { return (a == 0) ? b : gcd(b % a, a); }
long long cnt1(long long x) {
  long long cnt = 0;
  while (x > 0) x &= x - 1, cnt++;
  return cnt;
}
long long fact(long long n) { return n == 0 ? 1LL : n * fact(n - 1); }
long long fact(long long n, long long p) {
  return n == 0 ? 1LL : n * fact(n - 1) % p;
}
long long cnk(long long n, long long k) {
  return n == 1 || k == 1 ? 1 : cnk(n - 1, k) + cnk(n - 1, k - 1);
}
long long pow(long long a, long long n, long long p) {
  if (n == 0) return 1;
  long long t = pow(a, n / 2, p);
  return t * t * (n % 2 ? a : 1);
}
long long cnk(long long n, long long k, long long p) {
  return fact(n, p) * pow(fact(k, p), p - 2, p) * pow(fact(n - k, p), p - 2, p);
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (long long i = 0; i < v.size(); i++) is >> v[i];
  return is;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> v) {
  for (long long i = 0; i < v.size(); i++) os << v[i] << ' ';
  os << '\n';
  return os;
}
const long long N = 1e+5 + 10, LOG = 20;
vector<long long> a;
long long tin[N], h[N];
vector<long long> gr[N];
void dfs(long long v, long long curh = 0) {
  h[v] = curh;
  tin[v] = a.size();
  a.push_back(v);
  for (long long u : gr[v]) dfs(u, curh + 1);
}
long long p[N][LOG];
long long lca(long long a, long long b) {
  if (h[a] > h[b]) swap(a, b);
  for (long long log = LOG - 1; log >= 0; log--)
    if (h[b] - (1 << log) >= h[a]) b = p[b][log];
  if (a == b) return a;
  for (long long log = LOG - 1; log >= 0; log--)
    if (p[a][log] != p[b][log]) {
      a = p[a][log];
      b = p[b][log];
    }
  return p[a][0];
}
long long imax[1 << 18], imin[1 << 18];
void build(long long v, long long l, long long r) {
  if (r - l == 1)
    imax[v] = imin[v] = l;
  else {
    long long m = (r + l) >> 1;
    build(2 * v + 1, l, m);
    build(2 * v + 2, m, r);
    if (tin[imin[2 * v + 1]] < tin[imin[2 * v + 2]])
      imin[v] = imin[2 * v + 1];
    else
      imin[v] = imin[2 * v + 2];
    if (tin[imax[2 * v + 1]] > tin[imax[2 * v + 2]])
      imax[v] = imax[2 * v + 1];
    else
      imax[v] = imax[2 * v + 2];
  }
}
pair<long long, long long> get(long long v, long long l, long long r,
                               long long ql, long long qr) {
  if (qr <= l || r <= ql)
    return {-1, -1};
  else if (ql <= l && r <= qr)
    return {imin[v], imax[v]};
  else {
    long long m = (r + l) >> 1;
    auto x = get(2 * v + 1, l, m, ql, qr);
    auto y = get(2 * v + 2, m, r, ql, qr);
    pair<long long, long long> ans;
    if (x.first == -1)
      ans.first = y.first;
    else if (y.first == -1)
      ans.first = x.first;
    else {
      if (tin[x.first] < tin[y.first])
        ans.first = x.first;
      else
        ans.first = y.first;
    }
    if (x.second == -1)
      ans.second = y.second;
    else if (y.second == -1)
      ans.second = x.second;
    else {
      if (tin[x.second] > tin[y.second])
        ans.second = x.second;
      else
        ans.second = y.second;
    }
    return ans;
  }
}
long long n;
long long get_ans(long long l, long long r, long long er) {
  if (l == er) {
    auto tmp = get(0, 0, n, er + 1, r);
    return lca(tmp.first, tmp.second);
  } else if (r - 1 == er) {
    auto tmp = get(0, 0, n, l, er);
    return lca(tmp.first, tmp.second);
  }
  auto tmp1 = get(0, 0, n, l, er);
  long long lca1 = lca(tmp1.first, tmp1.second);
  auto tmp2 = get(0, 0, n, er + 1, r);
  long long lca2 = lca(tmp2.first, tmp2.second);
  return lca(lca1, lca2);
}
signed main() {
  srand(time(0));
  ios_base::sync_with_stdio(0), cin.tie(0);
  memset(p, -1, sizeof p);
  long long q;
  cin >> n >> q;
  for (long long i = 1; i < n; i++) {
    cin >> p[i][0];
    p[i][0]--;
    gr[p[i][0]].push_back(i);
  }
  dfs(0);
  build(0, 0, n);
  for (long long l = 1; l < LOG; l++)
    for (long long i = 0; i < n; i++) {
      if (p[i][l - 1] == -1) continue;
      p[i][l] = p[p[i][l - 1]][l - 1];
    }
  while (q--) {
    long long l, r;
    cin >> l >> r;
    l--;
    auto tmp = get(0, 0, n, l, r);
    long long lca1 = get_ans(l, r, tmp.first), lca2 = get_ans(l, r, tmp.second);
    if (h[lca1] > h[lca2])
      cout << tmp.first + 1 << ' ' << h[lca1];
    else
      cout << tmp.second + 1 << ' ' << h[lca2];
    cout << '\n';
  }
}