#include <bits/stdc++.h>
using namespace std;
bool cmp(long long a, long long b) { return (a > b); }
long long ceil(const long long &a, const long long &b) {
  if (a % b == 0) return a / b;
  return a / b + 1;
}
long long mod = 1000000007;
const long long N = 200005;
long long LCA[N][20];
long long lvl[N];
vector<long long> adj[N];
long long n;
void dfs(long long u, long long p, long long l = 0) {
  LCA[u][0] = p;
  lvl[u] = l;
  for (long long v : adj[u]) {
    if (v != p) {
      dfs(v, u, l + 1);
    }
  }
}
void preprocess_LCA() {
  dfs(1, 0);
  for (long long j = 1; j < 20; j++) {
    for (long long i = 1; i <= n; i++) {
      long long par = LCA[i][j - 1];
      LCA[i][j] = LCA[par][j - 1];
    }
  }
}
long long lca(long long u, long long v) {
  if (lvl[u] < lvl[v]) {
    swap(v, u);
  }
  long long diff = lvl[u] - lvl[v];
  for (long long i = 19; i >= 0; i--) {
    if ((diff & (1 << i))) {
      u = LCA[u][i];
    }
  }
  if (u == v) {
    return u;
  }
  for (long long i = 19; i >= 0; i--) {
    if (LCA[u][i] != LCA[v][i]) {
      u = LCA[u][i];
      v = LCA[v][i];
    }
  }
  return LCA[u][0];
}
long long solve(long long a, long long b, long long c) {
  long long x = lvl[a] + lvl[b] - 2 * lvl[lca(a, b)];
  long long y = lvl[b] + lvl[c] - 2 * lvl[lca(b, c)];
  long long z = lvl[a] + lvl[c] - 2 * lvl[lca(a, c)];
  long long k = x + z - y;
  k /= 2;
  return k;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> n >> q;
  for (long long i = 2; i <= n; i++) {
    long long x;
    cin >> x;
    adj[i].push_back(x);
    adj[x].push_back(i);
  }
  preprocess_LCA();
  while (q--) {
    long long a, b, c;
    cin >> a >> b >> c;
    long long ans = 0;
    ans = max(ans, solve(a, b, c));
    ans = max(ans, solve(b, c, a));
    ans = max(ans, solve(c, a, b));
    cout << ans + 1;
    cout << '\n';
    ;
  }
  return 0;
}
