#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20, LOG = 20;
vector<int> adj[N];
int p[N][LOG], n, T, in[N], out[N];
long long int L[N];
void dfs(int u, int par) {
  p[u][0] = par;
  in[u] = T++;
  for (int i = 0; i < (int)adj[u].size(); i++) {
    int v = adj[u][i];
    if (v != par) {
      L[v] = L[u] + 1;
      dfs(v, u);
    }
  }
  out[u] = T - 1;
}
void pre() {
  memset(p, -1, sizeof p);
  dfs(0, -1);
  for (int j = 1; j < LOG; j++)
    for (int i = 0; i < n; i++) {
      if (p[i][j - 1] != -1) p[i][j] = p[p[i][j - 1]][j - 1];
    }
}
int getLca(int u, int v) {
  if (L[v] < L[u]) swap(u, v);
  for (int j = LOG - 1; ~j; j--) {
    if (L[v] - (1 << j) >= L[u]) v = p[v][j];
  }
  if (u == v) return u;
  for (int j = LOG - 1; ~j; j--) {
    if (p[u][j] != p[v][j]) {
      u = p[u][j];
      v = p[v][j];
    }
  }
  return p[v][0];
}
long long int getDist(int u, int v) {
  return L[u] + L[v] - 2 * L[getLca(u, v)];
}
bool under(int x, int y) { return in[x] < in[y] && in[y] <= out[x]; }
int solve(int f, int s, int t) {
  int fs = getLca(f, s), ft = getLca(f, t);
  if (under(f, s) && under(f, t)) return getDist(getLca(s, t), f);
  if (under(f, s) || under(f, t) || f == s || f == t) return 0;
  if (under(fs, ft) || under(ft, fs))
    return min(getDist(fs, f), getDist(ft, f));
  while (fs != ft)
    ;
  return getDist(fs, f) + getDist(getLca(s, t), fs);
}
int main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i < n; i++) {
    int u;
    scanf("%d", &u);
    u--;
    adj[u].push_back(i);
    adj[i].push_back(u);
  }
  pre();
  while (q--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--, c--;
    printf("%d\n",
           1 + max(solve(b, a, c), max(solve(c, a, b), solve(a, b, c))));
  }
  return 0;
}
