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;
template <typename A>
ostream& operator<<(ostream& cout, vector<A> const& v);
template <typename A, typename B>
ostream& operator<<(ostream& cout, pair<A, B> const& p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream& operator<<(ostream& cout, vector<A> const& v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
template <typename A, typename B>
istream& operator>>(istream& cin, pair<A, B>& p) {
  cin >> p.first;
  return cin >> p.second;
}
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}
struct lca_lift {
  const int lg = 24;
  int n;
  vector<int> depth;
  vector<vector<int>> edges;
  vector<vector<int>> lift;
  void init(int sz) {
    n = sz;
    depth = vector<int>(n);
    edges = vector<vector<int>>(n, vector<int>());
    lift = vector<vector<int>>(n, vector<int>(lg, -1));
  }
  void edge(int a, int b) {
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  void attach(int node_to_attach, int node_to_attach_to) {
    int a = node_to_attach, b = node_to_attach_to;
    edge(a, b);
    lift[a][0] = b;
    for (int i = 1; i < lg; i++) {
      if (lift[a][i - 1] == -1)
        lift[a][i] = -1;
      else
        lift[a][i] = lift[lift[a][i - 1]][i - 1];
    }
    depth[a] = depth[b] + 1;
  }
  void init_lift(int v = 0) {
    depth[v] = 0;
    dfs(v, -1);
  }
  void dfs(int v, int par) {
    lift[v][0] = par;
    for (int i = 1; i < lg; i++) {
      if (lift[v][i - 1] == -1)
        lift[v][i] = -1;
      else
        lift[v][i] = lift[lift[v][i - 1]][i - 1];
    }
    for (int x : edges[v]) {
      if (x != par) {
        depth[x] = depth[v] + 1;
        dfs(x, v);
      }
    }
  }
  int get(int v, int k) {
    for (int i = lg - 1; i >= 0; i--) {
      if (v == -1) return v;
      if ((1 << i) <= k) {
        v = lift[v][i];
        k -= (1 << i);
      }
    }
    return v;
  }
  int get_lca(int a, int b) {
    if (depth[a] < depth[b]) swap(a, b);
    int d = depth[a] - depth[b];
    int v = get(a, d);
    if (v == b) {
      return v;
    } else {
      for (int i = lg - 1; i >= 0; i--) {
        if (lift[v][i] != lift[b][i]) {
          v = lift[v][i];
          b = lift[b][i];
        }
      }
      return lift[b][0];
    }
  }
  int get_dist(int a, int b) {
    int v = get_lca(a, b);
    return depth[a] + depth[b] - 2 * depth[v];
  }
} lca;
template <typename num_t>
struct segtree_ind {
  int n, depth;
  vector<num_t> tree, lazy;
  void init(int second, long long* arr) {
    n = second;
    tree = vector<num_t>(4 * second, 0);
    lazy = vector<num_t>(4 * second, 0);
    init(0, 0, n - 1, arr);
  }
  num_t init(int i, int l, int r, long long* arr) {
    if (l == r) return tree[i] = num_t(arr[l], l);
    int mid = (l + r) / 2;
    num_t a = init(2 * i + 1, l, mid, arr),
          b = init(2 * i + 2, mid + 1, r, arr);
    return tree[i] = a.op(b);
  }
  num_t query(int l, int r) { return query(0, 0, n - 1, l, r); }
  num_t query(int i, int tl, int tr, int ql, int qr) {
    if (ql <= tl && tr <= qr) return tree[i];
    if (tl > tr || tr < ql || qr < tl) return num_t::null_v;
    int mid = (tl + tr) / 2;
    num_t a = query(2 * i + 1, tl, mid, ql, qr),
          b = query(2 * i + 2, mid + 1, tr, ql, qr);
    return a.op(b);
  }
};
struct min_t {
  long long val;
  int ind;
  static const long long null_v = 9223372036854775807LL;
  min_t() : val(0) {}
  min_t(long long v) : val(v) {}
  min_t(long long v, int i) : val(v), ind(i){};
  min_t op(min_t& other) {
    if (other.val == val) return (ind > other.ind) ? other : *this;
    return (val > other.val) ? other : *this;
  }
  min_t lazy_op(min_t v, int size) { return min_t(val + v.val, ind); }
};
struct max_t {
  long long val;
  int ind;
  static const long long null_v = -9223372036854775807LL;
  max_t() : val(0) {}
  max_t(long long v) : val(v) {}
  max_t(long long v, int i) : val(v), ind(i){};
  max_t op(max_t& other) {
    if (other.val == val) return (ind > other.ind) ? other : *this;
    return (val < other.val) ? other : *this;
  }
  max_t lazy_op(max_t v, int size) { return max_t(val + v.val, ind); }
};
struct lca_t {
  long long val;
  int ind;
  static const long long null_v = -1;
  lca_t() : val(-1) {}
  lca_t(long long v) : val(v) {}
  lca_t(long long v, int i) : val(v), ind(i){};
  lca_t op(lca_t& other) {
    if (val == -1) return other;
    if (other.val == -1) return *this;
    return lca_t(lca.get_lca(val, other.val), ind);
  }
  lca_t lazy_op(lca_t v, int size) { return v; }
};
long long n, m, q, k, l, r, x, y, z;
const long long template_array_size = 1e6 + 15075;
long long a[template_array_size];
long long b[template_array_size];
long long c[template_array_size];
string second, t;
vector<long long> ch[100005];
segtree_ind<max_t> mx;
segtree_ind<min_t> mn;
segtree_ind<lca_t> lc;
long long st[100005], en[100005], tv = -1;
void dfs(long long v) {
  st[v] = ++tv;
  for (long long x : ch[v]) dfs(x);
  en[v] = tv;
}
void solve(int tc = 0) {
  cin >> n >> q;
  lca.init(n);
  for (long long i = 0; i < n - 1; i++) {
    cin >> x;
    --x;
    ch[x].push_back(i + 1);
    lca.edge(x, i + 1);
  }
  lca.init_lift();
  dfs(0);
  for (long long i = 0; i < n; i++) a[i] = st[i];
  mx.init(n, a);
  mn.init(n, a);
  iota(b, b + n, 0);
  lc.init(n, b);
  for (long long i = 0; i < q; i++) {
    cin >> l >> r;
    --l;
    --r;
    long long mnv = mn.query(l, r).ind;
    long long mxv = mx.query(l, r).ind;
    long long curv = -1, curi = -1;
    {
      long long cur = -1;
      if (mnv > l) {
        cur = lc.query(l, mnv - 1).val;
      }
      if (mnv < r) {
        long long v = lc.query(mnv + 1, r).val;
        if (cur == -1)
          cur = v;
        else
          cur = lca.get_lca(cur, v);
      }
      curv = lca.depth[cur];
      curi = mnv;
    }
    {
      long long cur = -1;
      if (mxv > l) {
        cur = lc.query(l, mxv - 1).val;
      }
      if (mxv < r) {
        long long v = lc.query(mxv + 1, r).val;
        if (cur == -1)
          cur = v;
        else
          cur = lca.get_lca(cur, v);
      }
      if (lca.depth[cur] > curv) {
        curv = lca.depth[cur];
        curi = mxv;
      }
    }
    cout << curi + 1 << " " << curv << '\n';
  }
}
int main() {
  { ios_base::sync_with_stdio(false); }
  { cin.tie(NULL); }
  cout << setprecision(15) << fixed;
  int tc = 1;
  for (int t = 0; t < tc; t++) solve(t);
}