#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
vector<vector<int> > V;
bool vis[N];
int par[N][20];
int level[N];
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < V[u].size(); i++) {
    if (!vis[V[u][i]]) {
      vis[V[u][i]] = 1;
      par[V[u][i]][0] = u;
      level[V[u][i]] = level[u] + 1;
      dfs(V[u][i]);
    }
  }
}
int LCA(int a, int b) {
  if (level[a] > level[b]) swap(a, b);
  for (int j = 19; j >= 0; j--) {
    if (level[b] - (1 << j) >= level[a]) {
      b = par[b][j];
    }
  }
  if (a == b) return a;
  for (int j = 19; j >= 0; j--) {
    if (par[a][j] != par[b][j] && par[b][j] != 0 && par[a][j] != 0) {
      a = par[a][j];
      b = par[b][j];
    }
  }
  return par[a][0];
}
int len(int a, int b) {
  if (level[a] > level[b]) swap(a, b);
  int sum = 0;
  for (int j = 19; j >= 0; j--) {
    if (level[b] - (1 << j) >= level[a]) {
      b = par[b][j];
      sum += (1 << j);
    }
  }
  return sum;
}
int main() {
  int n, m, X;
  cin >> n >> m;
  V.resize(n + 1);
  for (int i = 2; i <= n; i++) {
    cin >> X;
    V[i].push_back(X);
    V[X].push_back(i);
  }
  dfs(1);
  for (int j = 1; j < 20; j++)
    for (int i = 1; i <= n; i++) par[i][j] = par[par[i][j - 1]][j - 1];
  int a, b, c;
  int x, y, z;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    x = LCA(a, b);
    y = LCA(a, c);
    z = LCA(b, c);
    if (x == y && y == z) {
      cout << max(len(x, a), max(len(x, b), len(x, c))) + 1;
    } else {
      if (z == y) {
        cout << max(len(x, z) + len(c, z), max(len(x, a), len(x, b))) + 1;
      } else if (z == x) {
        cout << max(len(y, z) + len(b, z), max(len(y, a), len(y, c))) + 1;
      } else if (x == y) {
        cout << max(len(x, z) + len(a, x), max(len(z, c), len(z, b))) + 1;
      }
    }
    cout << endl;
  }
  return 0;
}
