#include <bits/stdc++.h>
int n, q;
using namespace std;
const int N = 120005;
int fa[N];
map<pair<int, int>, int> Q;
map<pair<int, int>, int> Ans;
bool vis[N];
int root;
struct Edge {
  int u, v, nxt, ans;
} e[N * 2], ans[N * 6];
int cnt, cntq;
int h[N], hq[N];
void init() {
  memset(h, -1, sizeof(h));
  memset(hq, -1, sizeof(hq));
  cnt = cntq = 0;
}
void add(int u, int v) {
  e[cnt].v = v;
  e[cnt].nxt = h[u];
  h[u] = cnt++;
}
void addq(int u, int v) {
  ans[cntq].ans = 0;
  ans[cntq].v = v;
  ans[cntq].nxt = hq[u];
  hq[u] = cntq++;
}
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void tarjan(int u, int pre) {
  int v;
  fa[u] = u;
  for (int k = h[u]; ~k; k = e[k].nxt) {
    v = e[k].v;
    if (v == pre) continue;
    tarjan(v, u);
    fa[v] = u;
  }
  vis[u] = true;
  for (int k = hq[u]; ~k; k = ans[k].nxt) {
    v = ans[k].v;
    if (vis[v]) {
      Ans[make_pair(u, v)] = Ans[make_pair(v, u)] = find(v);
    }
  }
}
int t;
const int maxn = 120000;
int deep[maxn];
int a[maxn], b[maxn], c[maxn];
void dfs(int u, int pos, int pre) {
  deep[u] = pos;
  for (int i = h[u]; i != -1; i = e[i].nxt) {
    int v = e[i].v;
    if (v == pre) continue;
    dfs(v, pos + 1, u);
  }
}
int main() {
  memset(h, -1, sizeof(h));
  memset(hq, -1, sizeof(hq));
  scanf("%d%d", &n, &q);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &t);
    add(i, t);
    add(t, i);
  }
  dfs(1, 0, 1);
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    addq(a[i], b[i]);
    addq(b[i], a[i]);
    addq(b[i], c[i]);
    addq(c[i], b[i]);
    addq(a[i], c[i]);
    addq(c[i], a[i]);
  }
  tarjan(1, 1);
  for (int i = 1; i <= q; i++) {
    int lab =
        deep[a[i]] + deep[b[i]] - 2 * deep[Ans[pair<int, int>(a[i], b[i])]];
    int lac =
        deep[a[i]] + deep[c[i]] - 2 * deep[Ans[pair<int, int>(a[i], c[i])]];
    int lbc =
        deep[b[i]] + deep[c[i]] - 2 * deep[Ans[pair<int, int>(b[i], c[i])]];
    int p = (lab + lac + lbc) / 2;
    int x = p - lab;
    int y = p - lac;
    int z = p - lbc;
    printf("%d\n", max(x, max(y, z)) + 1);
  }
  return 0;
}
