#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
int n, q, cnt;
int d[100001];
int head[100001], p[100001][21];
using namespace std;
struct fuck {
  int to, next;
} e[100001 * 2];
template <class T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x *= f;
}
void add(int u, int v) {
  e[cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
void init() {
  cnt = 0;
  memset(head, -1, sizeof(head));
}
void dfs(int u, int dad) {
  d[u] = d[dad] + 1;
  p[u][0] = dad;
  for (int i = 1; i <= 20; i++) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i = head[u]; ~i; i = e[i].next) {
    int j = e[i].to;
    if (j == dad) continue;
    dfs(j, u);
  }
}
int LCA(int a, int b) {
  if (d[a] > d[b]) swap(a, b);
  for (int i = 20; i >= 0; i--)
    if (d[a] <= d[b] - (1 << i)) b = p[b][i];
  if (a == b) return a;
  for (int i = 20; i >= 0; i--) {
    if (p[a][i] == p[b][i]) continue;
    a = p[a][i];
    b = p[b][i];
  }
  return p[a][0];
}
int main() {
  init();
  int v;
  int a, b, c;
  read(n);
  read(q);
  for (int i = 2; i <= n; i++) {
    read(v);
    add(i, v);
    add(v, i);
  }
  dfs(1, 0);
  while (q--) {
    read(a);
    read(b);
    read(c);
    int sab = d[a] + d[b] - 2 * d[LCA(a, b)];
    int sbc = d[b] + d[c] - 2 * d[LCA(b, c)];
    int sac = d[a] + d[c] - 2 * d[LCA(a, c)];
    int s1 = (sab + sbc - sac) / 2;
    int s2 = (-sab + sbc + sac) / 2;
    int s3 = (sab - sbc + sac) / 2;
    printf("%d\n", max(s1, max(s2, s3)) + 1);
  }
  return 0;
}
