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 comment(linker, "/stack:225450978")
#pragma GCC optimize("Ofast")
using namespace std;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9,
                  Gold = ((1 + sqrt(5)) / 2);
long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
long long keyCount = sizeof(keymod) / sizeof(long long);
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcountll(s);
}
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
string cppstr_infile = "FILE.IN";
string cppstr_outfile = "FILE.OUT";
long long n, q, l, r;
vector<long long> p, d, Log2;
vector<vector<long long> > adj, Table, TableLCA;
void DFS(long long z, long long last) {
  if (z != 0) d[z] = d[last] + 1;
  for (auto t : adj[z]) {
    if (t == last) continue;
    DFS(t, z);
    Table[t].push_back(z);
  }
}
void PreprocessNormal() {
  Table.resize(n);
  d.resize(n, 0);
  DFS(0, -1);
  for (long long j = 1; j < 17; j++) {
    for (long long i = 0; i < n; i++) {
      if (Table[i].size() < j) continue;
      if (Table[Table[i][j - 1]].size() < j) continue;
      Table[i].push_back(Table[Table[i][j - 1]][j - 1]);
    }
  }
}
long long LCA(long long x, long long y) {
  if (x == y) return x;
  if (d[x] == d[y]) {
    long long id = 0, Init = min(Table[x].size(), Table[y].size() - 1);
    for (long long i = Init; i >= 0; i--) {
      if (Table[x][i] != Table[y][i]) {
        id = i;
        break;
      }
    }
    return LCA(Table[x][id], Table[y][id]);
  }
  if (d[x] < d[y]) {
    long long mul = 1, id = 0;
    while (d[x] < d[y] - mul * 2) {
      mul *= 2;
      id++;
    }
    return LCA(x, Table[y][id]);
  }
  if (d[x] > d[y]) {
    long long mul = 1, id = 0;
    while (d[y] < d[x] - mul * 2) {
      mul *= 2;
      id++;
    }
    return LCA(Table[x][id], y);
  }
}
void PreprocessTableLCA() {
  TableLCA.resize(n);
  for (long long i = 0; i < n; i++) TableLCA[i].push_back(i);
  for (long long j = 1; j < 17; j++) {
    for (long long i = 0; i < n; i++) {
      if (TableLCA[i].size() < j) continue;
      if (i + (1LL << (j - 1)) >= n) continue;
      if (TableLCA[i + (1LL << (j - 1))].size() < j) continue;
      TableLCA[i].push_back(
          LCA(TableLCA[i][j - 1], TableLCA[i + (1LL << (j - 1))][j - 1]));
    }
  }
}
long long LCASegment(long long L, long long R) {
  long long x = log2(R - L + 1);
  return LCA(TableLCA[L][x], TableLCA[R - (1LL << x) + 1][x]);
}
long long binsearch_prefix(long long L, long long R, long long Anc) {
  long long top = L, bot = R, ans = L;
  while (top <= bot) {
    long long mid = (top + bot) / 2;
    if (LCASegment(L, mid) == Anc) {
      ans = mid;
      bot = mid - 1;
    } else
      top = mid + 1;
  }
  return ans;
}
long long binsearch_suffix(long long L, long long R, long long Anc) {
  long long top = L, bot = R, ans = R;
  while (top <= bot) {
    long long mid = (top + bot) / 2;
    if (LCASegment(mid, R) == Anc) {
      ans = mid;
      top = mid + 1;
    } else
      bot = mid - 1;
  }
  return ans;
}
long long ProceedAnswer(long long L, long long R, long long x) {
  if (L < x && x < R) return LCA(LCASegment(L, x - 1), LCASegment(x + 1, R));
  if (L == x) return LCASegment(x + 1, R);
  return LCASegment(L, x - 1);
}
void Input() {
  cin >> n >> q;
  p.resize(n, -1);
  adj.resize(n);
  for (long long i = 1; i < n; i++) {
    cin >> p[i];
    p[i]--;
    adj[p[i]].push_back(i);
    adj[i].push_back(p[i]);
  }
}
void Solve() {
  PreprocessNormal();
  PreprocessTableLCA();
  while (q--) {
    cin >> l >> r;
    l--;
    r--;
    long long TotalLCA = LCASegment(l, r);
    long long l1 = binsearch_prefix(l, r, TotalLCA),
              r1 = binsearch_suffix(l, r, TotalLCA);
    long long LCA_l1 = ProceedAnswer(l, r, l1),
              LCA_r1 = ProceedAnswer(l, r, r1);
    if (d[LCA_l1] > d[LCA_r1])
      cout << l1 + 1 << " " << d[LCA_l1] << '\n';
    else
      cout << r1 + 1 << " " << d[LCA_r1] << '\n';
  }
}
int main(int argc, char* argv[]) {
  ControlIO(argc, argv);
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  Input();
  TimerStart();
  Solve();
  TimerStop();
  return 0;
}
void ControlIO(int argc, char* argv[]) {
  char* infile = new char[cppstr_infile.size() + 1];
  char* outfile = new char[cppstr_outfile.size() + 1];
  strcpy(infile, cppstr_infile.c_str());
  strcpy(outfile, cppstr_outfile.c_str());
}
void TimerStart() {}
void TimerStop() {}
void Exit() {
  TimerStop();
  exit(0);
}