#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int f[N][20], dep[N], n, m, s;
vector<int> G[N];
void dfs(int u, int fa, int d) {
  dep[u] = d;
  f[u][0] = fa;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v == fa) {
      continue;
    }
    dfs(v, u, d + 1);
  }
}
int dist(int x, int y) {
  int len = 0;
  if (dep[x] < dep[y]) {
    swap(x, y);
  }
  for (int i = 19; i >= 0; --i) {
    if (dep[f[x][i]] >= dep[y]) {
      x = f[x][i];
      len += (1 << i);
    }
  }
  if (x == y) {
    return len;
  }
  for (int i = 19; i >= 0; --i) {
    if (f[x][i] != f[y][i]) {
      x = f[x][i];
      y = f[y][i];
      len += 2 * (1 << i);
    }
  }
  return len + 2;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) {
    int p;
    scanf("%d", &p);
    G[i + 1].push_back(p);
    G[p].push_back(i + 1);
  }
  dfs(1, 0, 1);
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i <= n; ++i) {
      f[i][j] = f[f[i][j - 1]][j - 1];
    }
  }
  while (m--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int lab = dist(a, b);
    int lac = dist(a, c);
    int lbc = dist(b, c);
    int l1 = (lab + lbc - lac) / 2 + 1;
    int l2 = (lab + lac - lbc) / 2 + 1;
    int l3 = (lac + lbc - lab) / 2 + 1;
    printf("%d\n", max(l1, max(l2, l3)));
  }
  return 0;
}
