#include <bits/stdc++.h>
using namespace std;
int par[200004][22];
vector<int> adj[234567];
int h[234567];
void dfs(int v, int p = -1) {
  par[v][0] = p;
  if (p + 1) h[v] = h[p] + 1;
  for (int i = 1; i < 22; i++) {
    if (par[v][i - 1] + 1) par[v][i] = par[par[v][i - 1]][i - 1];
  }
  for (auto u : adj[v]) {
    if (p - u) dfs(u, v);
  }
}
int LCA(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = 21; i >= 0; i--) {
    if (par[v][i] + 1 && h[par[v][i]] >= h[u]) v = par[v][i];
  }
  if (v == u) return v;
  for (int i = 21; i >= 0; i--) {
    if (par[v][i] - par[u][i]) {
      v = par[v][i];
      u = par[u][i];
    }
  }
  return par[v][0];
}
int get(int u, int v) { return h[u] + h[v] - 2 * h[LCA(u, v)]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int a;
    cin >> a;
    adj[a].push_back(i);
    adj[i].push_back(a);
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= 22; j++) par[i][j] = -1;
  }
  dfs(1);
  while (q--) {
    int s1[3], ans = 1;
    cin >> s1[0] >> s1[1] >> s1[2];
    for (int i = 0; i < 3; i++) {
      int s = s1[i];
      for (int j = 0; j < 3; j++) {
        if (j == i) continue;
        int f = s1[j];
        for (int k = 0; k < 3; k++) {
          if (k == i || k == j) continue;
          int t = s1[k];
          int n1 = LCA(s, f);
          int n2 = LCA(f, t);
          if (n1 == n2)
            ans = max(ans, get(LCA(s, t), f) + 1);
          else {
            if (LCA(n1, n2) == n2) ans = max(ans, get(n1, f) + 1);
            if (LCA(n1, n2) == n1) ans = max(ans, get(n2, f) + 1);
          }
        }
      }
    }
    cout << ans << "\n";
  }
}
