#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g(100010);
int depth[100010];
int pa[100010][21];
void dfs(int cur, int prev, int dep) {
  pa[cur][0] = prev;
  depth[cur] = dep;
  for (int i = 0; i < (int)g[cur].size(); ++i) {
    if (g[cur][i] != prev) {
      dfs(g[cur][i], cur, dep + 1);
    }
  }
}
int lca(int u, int v) {
  if (depth[u] < depth[v]) {
    swap(u, v);
  }
  int d = depth[u] - depth[v];
  for (int i = 0; i < 20; ++i) {
    if ((d >> i) & 1) {
      u = pa[u][i];
    }
  }
  if (u == v) {
    return u;
  }
  for (int i = 19; i >= 0; --i) {
    if (pa[u][i] != pa[v][i]) {
      u = pa[u][i];
      v = pa[v][i];
    }
  }
  return pa[u][0];
}
int f(int u, int v, int w) {
  int l1 = lca(u, v), l2 = lca(v, w), l3 = lca(u, w);
  if (l1 == v && l2 == v) {
    return depth[l3] - depth[v] + 1;
  }
  long long int d1 = depth[v] - depth[l1], d2 = depth[v] - depth[l2];
  if (d1 * d2 <= 0) {
    return 1;
  }
  int ret = 0;
  if (d1 < d2) {
    ret += d1 + 1;
    if (depth[l1] < depth[l3]) {
      ret += depth[l3] - depth[l1];
    }
  } else {
    ret += d2 + 1;
    if (depth[l2] < depth[l3]) {
      ret += depth[l3] - depth[l2];
    }
  }
  return ret;
}
int main(void) {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i < n; ++i) {
    int p;
    cin >> p;
    g[i].push_back(--p);
    g[p].push_back(i);
  }
  for (int i = 0; i < 21; ++i) {
    for (int j = 0; j < n; ++j) {
      pa[j][i] = -1;
    }
  }
  dfs(0, -1, 0);
  for (int i = 1; i < 20; ++i) {
    for (int j = 0; j < n; ++j) {
      if (pa[j][i - 1] != -1) {
        pa[j][i] = pa[pa[j][i - 1]][i - 1];
      }
    }
  }
  for (int i = 0; i < q; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    --c;
    int a1 = f(a, b, c), a2 = f(a, c, b), a3 = f(b, a, c), a4 = f(b, c, a),
        a5 = f(c, a, b), a6 = f(c, b, a);
    cout << max(a1, max(a2, max(a3, max(a4, max(a5, a6))))) << '\n';
  }
}
