#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const long long INF = 1e18 + 1LL;
const int inf = 1e9 + 1e8;
const int N = 2e5 + 100;
const long long mod = 1e9 + 7;
struct Edge {
  int next, to;
};
Edge e[N];
int n, q;
int siz[N], son[N], tip[N], fa[N], dep[N], ran[N], top[N], cnt;
int head[N], tot;
int C[N];
void add(int u, int v) {
  e[tot].to = v;
  e[tot].next = head[u];
  head[u] = tot++;
}
void dfs1(int u, int f) {
  siz[u] = 1;
  fa[u] = f;
  dep[u] = dep[f] + 1;
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].to;
    if (v == f) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int tp) {
  tip[u] = ++cnt;
  top[u] = tp;
  if (son[u]) dfs2(son[u], tp);
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].to;
    if (v != son[u] && v != fa[u]) dfs2(v, v);
  }
}
int lowbit(int x) { return (-x) & x; }
void add(int x) {
  while (x <= n) {
    C[x] += 1;
    x += lowbit(x);
  }
}
int sum(int l, int r) {
  int ret = 0;
  l--;
  while (r > 0) {
    ret += C[r];
    r -= lowbit(r);
  }
  while (l > 0) {
    ret -= C[l];
    l -= lowbit(l);
  }
  return ret;
}
int query(int u, int v) {
  int ans = 0;
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    ans += sum(tip[top[u]], tip[u]);
    u = fa[top[u]];
  }
  if (dep[u] > dep[v]) swap(u, v);
  ans += sum(tip[u], tip[v]);
  return ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  memset(head, -1, sizeof(head));
  int to;
  for (int i = 2; i <= n; ++i) {
    cin >> to;
    add(i, to);
    add(to, i);
  }
  for (int i = 1; i <= 2 * n; ++i) {
    add(i);
  }
  dfs1(1, 1);
  dfs2(1, 1);
  int a, b, c, ans[5], anss;
  while (q--) {
    cin >> a >> b >> c;
    ans[0] = query(a, b);
    ans[1] = query(a, c);
    ans[2] = query(b, c);
    sort(ans, ans + 3);
    anss = ans[1] + ans[2] + 1 - ans[0] >> 1;
    cout << anss << "\n";
  }
  return 0;
}
