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 optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
template <typename t>
void f(const char* x, t&& val1) {
  cout << x << " : " << val1 << endl;
}
template <typename t1, typename... t2>
void f(const char* x, t1&& val1, t2&&... val2) {
  const char* xd = strchr(x + 1, ',');
  cout.write(x, xd - x) << " : " << val1 << " | ";
  f(xd + 1, val2...);
}
struct HLDES {
  int n, gid;
  int tsz[300005], rt[300005], d[300005], id[300005], p[300005];
  vector<int> adj[300005], eu;
  int l[300005], r[300005];
  inline int dfs(int u, int pp, int depth) {
    d[u] = depth, p[u] = pp, tsz[u] = 1;
    eu.push_back(u);
    if (l[u] == 0) l[u] = gid++;
    for (auto xd : adj[u])
      if (xd != pp) tsz[u] += dfs(xd, u, depth + 1), eu.push_back(u), gid++;
    if (int(adj[u].size()) == 1) eu.push_back(u), gid++;
    r[u] = gid;
    return tsz[u];
  }
  inline void make() {
    int pe = dfs(0, -1, 0);
    gid = 0;
  }
  inline void go(int u, int root) {
    id[u] = gid++, rt[u] = root;
    int w = -1, bc = 0;
    for (auto xd : adj[u])
      if (xd != p[u] && w < tsz[xd]) bc = xd, w = tsz[xd];
    if (bc) go(bc, root);
    for (auto xd : adj[u])
      if (xd != p[u] && xd != bc) go(xd, xd);
  }
  inline int lca(int a, int b) {
    while (rt[a] != rt[b]) d[rt[a]] > d[rt[b]] ? a = p[rt[a]] : b = p[rt[b]];
    return d[a] > d[b] ? b : a;
  }
  inline void build() {
    gid = 0;
    make();
    go(0, 0);
  }
} hld;
struct T {
  int nod, t1;
  T() {}
  T(int nod, int t1) : nod(nod), t1(t1){};
  inline void clear() { t1 = -1; }
};
struct ST {
  int n;
  T t[300005 << 1];
  inline T Op(T& val1, T& val2) {
    T ty;
    if (val1.t1 == -1) return val2;
    if (val2.t1 == -1) return val1;
    val1.t1 > val2.t1 ? (ty.nod = val2.nod, ty.t1 = val2.t1)
                      : (ty.nod = val1.nod, ty.t1 = val1.t1);
    return ty;
  }
  inline void build() {
    for (int i = int(n - 1); i >= int(1); --i)
      t[i] = Op(t[i << 1], t[i << 1 | 1]);
  }
  inline void modify(int p, T val) {
    for (t[p += n] = val; p >>= 1;) t[p] = Op(t[p << 1], t[p << 1 | 1]);
  }
  inline T que(int l, int r) {
    T ansl, ansr;
    ansl.clear(), ansr.clear();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ansl = Op(ansl, t[l++]);
      if (r & 1) ansr = Op(t[--r], ansr);
    }
    return Op(ansl, ansr);
  }
} st, st2, st3;
inline pair<int, int> ja(int a, int b) {
  if (a > b) return {-1, -1};
  if (a == b) {
    pair<int, int> cur;
    cur.first = a;
    cur.second = hld.d[a];
    return cur;
  }
  T x = st2.que(a, b + 1), y = st3.que(a, b + 1);
  int iz = x.nod, der = y.nod;
  int l = x.t1, r = -y.t1 + 1;
  T cur = st.que(l, r);
  return {cur.nod, cur.t1};
}
inline pair<int, int> solve(pair<int, int> cur1, pair<int, int> cur2) {
  pair<int, int> ans;
  if (cur1.first == -1 && cur1.second == -1) return cur2;
  if (cur2.first == -1 && cur2.second == -1) return cur1;
  int f1 = hld.lca(cur1.first, cur2.first), f2 = hld.d[f1];
  return {f1, f2};
}
inline void go(int a, int b) {
  T x = st2.que(a, b), y = st3.que(a, b);
  int iz = x.nod, der = y.nod;
  pair<int, int> cur1 = ja(a, iz - 1), cur2 = ja(iz + 1, b - 1);
  pair<int, int> t1 = ja(a, der - 1), t2 = ja(der + 1, b - 1);
  int froz1, froz2;
  pair<int, int> p1, p2;
  p1 = solve(cur1, cur2), p2 = solve(t1, t2);
  p2.second > p1.second ? (froz1 = p2.second, froz2 = der)
                        : (froz1 = p1.second, froz2 = iz);
  cout << froz2 + 1 << " " << froz1 << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  hld.n = n;
  for (int i = int(0); i < int(n - 1); ++i) {
    int a;
    cin >> a;
    a--;
    hld.adj[a].push_back(i + 1);
    hld.adj[i + 1].push_back(a);
  }
  hld.build();
  st.n = int(hld.eu.size());
  int pos = 0;
  for (auto xd : hld.eu) {
    st.t[pos + st.n].nod = xd;
    st.t[pos + st.n].t1 = hld.d[xd];
    pos++;
  }
  st.build();
  st2.n = n, st3.n = n;
  for (int i = int(0); i < int(n); ++i) {
    st2.t[i + st2.n].nod = i;
    st2.t[i + st2.n].t1 = hld.l[i];
    st3.t[i + st3.n].nod = i;
    st3.t[i + st3.n].t1 = -hld.l[i];
  }
  st2.build();
  st3.build();
  for (int i = int(0); i < int(q); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    go(a, b);
  }
  return 0;
}