#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
;
;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int m = 0, n, res, k, ans = 0, nbcycle = 0;
string s2 = "zero", ch = "", s, t, s1 = "";
set<int> st;
vector<pair<string, int> > vm;
vector<pair<int, pair<int, int> > > vvv;
vector<pair<int, int> > vv, vv2;
vector<int> v[200005], v2;
const long long int NMAX = 100001, LGNMAX = 25;
int seen[NMAX];
int depth[NMAX];
int parent[LGNMAX][NMAX];
int dp[NMAX], sum[NMAX], vis[NMAX] = {0};
int a[200005];
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < v[u].size(); ++i) {
    int z = v[u][i];
    if (vis[z]) continue;
    depth[z] = depth[u] + 1;
    parent[0][z] = u;
    dfs(z);
  }
}
void preprocess() {
  for (int i = 1; i < LGNMAX; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (parent[i - 1][j] != -1) {
        parent[i][j] = parent[i - 1][parent[i - 1][j]];
      }
    }
  }
}
int getparent(int u, int k) {
  for (int i = 0; i < LGNMAX; ++i) {
    if (k & 1) u = parent[i][u];
    k >>= 1;
  }
  return u;
}
int LCA(int u, int v) {
  if (depth[u] > depth[v]) {
    u = getparent(u, depth[u] - depth[v]);
  } else if (depth[v] > depth[u]) {
    v = getparent(v, depth[v] - depth[u]);
  }
  if (u == v) return u;
  for (int i = LGNMAX - 1; i >= 0; i--) {
    if (parent[i][u] != parent[i][v] && parent[i][u] != -1 &&
        parent[i][v] != -1) {
      u = parent[i][u];
      v = parent[i][v];
    }
  }
  return parent[0][v];
}
int solve(int s, int f, int t) {
  int x = LCA(s, f);
  if (x == f) {
    x = LCA(s, t);
    int y = LCA(x, f);
    if (y == f)
      return (abs(depth[f] - depth[x]) + 1);
    else
      return 1;
  } else if (x == s) {
    x = LCA(f, t);
    if (x == f) return 1;
    int y = LCA(x, s);
    if (y == s) {
      return (abs(depth[x] - depth[f]) + 1);
    } else {
      return (abs(depth[s] - depth[f]) + 1);
    }
  } else {
    x = LCA(s, f);
    int y = LCA(t, x);
    if (y == t) return (abs(depth[x] - depth[f]) + 1);
    int h = LCA(x, y);
    if (h == y && depth[h] < depth[x]) return (abs(depth[x] - depth[f]) + 1);
    int z = LCA(t, f);
    if (z == x) {
      int sz = LCA(s, t);
      return (depth[sz] - depth[x] + depth[f] - depth[x] + 1);
    }
    if (z == f) return 1;
    int w = LCA(z, x);
    if (w == z) return (abs(depth[x] - depth[f]) + 1);
    if (z != x) return (abs(depth[z] - depth[f]) + 1);
    w = LCA(s, t);
    if (w == x) return (abs(depth[x] - depth[f]) + 1);
    return (depth[w] + depth[f] - 2 * depth[x] + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int i = 0, x, y, j = 0, q, mm = 0, mx = 0, idx = 0, ok = 0, l = 0, r = 0,
      negatif = 0, positif = 0, l1, r1, d;
  set<int>::iterator it, it1;
  cin >> n >> q;
  memset(vis, 0, sizeof(vis));
  memset(parent, -1, sizeof(parent));
  memset(depth, 0, sizeof(depth));
  for (i = 2; i <= n; i++) {
    cin >> x;
    y = i;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1);
  preprocess();
  int nb = 0;
  while (q--) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    res = 1;
    do {
      res = max(res, solve(a[0], a[1], a[2]));
    } while (std::next_permutation(a, a + 3));
    cout << res << endl;
  }
  return 0;
}
