#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, Q;
vector<int> g[N];
int in[N], out[N];
int T;
int D[N];
int P[N][22];
void DFS(int k, int p) {
  in[k] = ++T;
  P[k][0] = p;
  D[k] = D[p] + 1;
  for (int i = 0; i < g[k].size(); i++)
    if (g[k][i] != p) DFS(g[k][i], k);
  out[k] = ++T;
}
int LCA(int u, int v) {
  if (in[u] <= in[v] && out[v] <= out[u]) return u;
  if (in[v] <= in[u] && out[u] <= out[v]) return v;
  int I = u;
  for (int i = 19; i >= 0; i--) {
    if (P[I][i] == 0) continue;
    if (in[P[I][i]] <= in[v] && out[v] <= out[P[I][i]]) continue;
    I = P[I][i];
  }
  return P[I][0];
}
int main() {
  cin >> n >> Q;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    g[i].push_back(p);
    g[p].push_back(i);
  }
  DFS(1, 0);
  for (int i = 1; (1 << i) <= n; i++)
    for (int j = 1; j <= n; j++) P[j][i] = P[P[j][i - 1]][i - 1];
  while (Q--) {
    int a, b, c;
    cin >> a >> b >> c;
    int x, y, z;
    x = LCA(b, c);
    y = LCA(a, c);
    z = LCA(a, b);
    if (x == z) {
      swap(b, c);
      swap(y, z);
    }
    if (y == z) {
      swap(a, c);
      swap(x, z);
    }
    cout << ((((D[a] - D[z] + 1) > (D[b] - D[z] + 1) ? (D[a] - D[z] + 1)
                                                     : (D[b] - D[z] + 1))) >
                     (D[z] + D[c] - 2 * D[x] + 1)
                 ? (((D[a] - D[z] + 1) > (D[b] - D[z] + 1) ? (D[a] - D[z] + 1)
                                                           : (D[b] - D[z] + 1)))
                 : (D[z] + D[c] - 2 * D[x] + 1))
         << endl;
  }
  return 0;
}
