#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct node {
  int v;
  int next;
} edge[200010];
int head[200010];
int lg[200010];
int depth[200010];
int fa[200010][20];
int n, q;
int tot;
void add(int u, int v) {
  edge[++tot].v = v;
  edge[tot].next = head[u];
  head[u] = tot;
}
void dfs(int f, int fath) {
  depth[f] = depth[fath] + 1;
  fa[f][0] = fath;
  for (int i = 1; (1 << i) <= depth[f]; i++) fa[f][i] = fa[fa[f][i - 1]][i - 1];
  for (int i = head[f]; i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fath) continue;
    dfs(v, f);
  }
}
int lca(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  while (depth[x] > depth[y]) x = fa[x][lg[depth[x] - depth[y]] - 1];
  if (x == y) return x;
  for (int k = lg[depth[x]] - 1; k >= 0; k--) {
    if (fa[x][k] == fa[y][k]) continue;
    x = fa[x][k], y = fa[y][k];
  }
  return fa[x][0];
}
int dist(int a, int b) {
  int u = lca(a, b);
  int l = depth[a] + depth[b] - 2 * depth[u];
  return l;
}
int main() {
  n = read();
  q = read();
  for (int i = 2; i <= n; i++) {
    int x;
    x = read();
    add(x, i);
    add(i, x);
  }
  for (int i = 1; i <= n; i++) lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);
  dfs(1, 1);
  for (int i = 1; i <= q; i++) {
    int a, b, c;
    a = read();
    b = read();
    c = read();
    int ans = 0;
    int lab, lbc, lac, l1, l2, l3;
    lac = dist(a, c);
    lab = dist(a, b);
    lbc = dist(b, c);
    l1 = (lab + lbc - lac) / 2;
    l2 = (lab + lac - lbc) / 2;
    l3 = (lac + lbc - lab) / 2;
    ans = max(l1, max(l2, l3));
    printf("%d\n", ans + 1);
  }
  return 0;
}
