#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u;
  edge* next;
  edge(int u = 0, edge* next = NULL) : u(u), next(next) {}
  void insert(int u) {
    if (this->next == NULL)
      this->next = new edge(u, NULL);
    else
      this->next = new edge(u, this->next);
  }
} e[100005];
int n, q, h[100005], G[100005][17];
void dfs(int, int);
int lca(int, int);
int main(void) {
  cin >> n >> q;
  for (int i = 2, u; i <= n; ++i) {
    cin >> u;
    e[i].insert(u);
    e[u].insert(i);
  }
  h[1] = 1;
  dfs(1, 1);
  int a, b, c;
  while (q--) {
    cin >> a >> b >> c;
    int aa = lca(a, b), bb = lca(b, c), cc = lca(a, c);
    int x = h[aa] > h[bb] ? aa : bb;
    x = h[x] > h[cc] ? x : cc;
    cout << max(h[x] + h[a] - 2 * h[lca(x, a)],
                max(h[x] + h[b] - 2 * h[lca(x, b)],
                    h[x] + h[c] - 2 * h[lca(x, c)])) +
                1
         << endl;
    ;
  }
}
int lca(int a, int b) {
  if (h[a] < h[b]) swap(a, b);
  if (h[a] != h[b]) {
    for (int i = 17 - 1; i >= 0; --i)
      if (h[G[a][i]] > h[b]) a = G[a][i];
    a = G[a][0];
  }
  if (a == b) return a;
  for (int i = 17 - 1; i >= 0; --i)
    if (G[a][i] != G[b][i]) a = G[a][i], b = G[b][i];
  return G[a][0];
}
void dfs(int s, int fa) {
  for (edge* n = e[s].next; n != NULL; n = n->next) {
    if (n->u == fa) continue;
    h[n->u] = h[s] + 1;
    G[n->u][0] = s;
    for (int i = 1; i < 17; ++i)
      if (G[G[n->u][i - 1]][i - 1]) G[n->u][i] = G[G[n->u][i - 1]][i - 1];
    dfs(n->u, s);
  }
}
