#include <bits/stdc++.h>
using namespace std;
const long long L = 21;
const long long N = 1e5 + 7;
const long long INF = 1e9 + 1;
const long long mod = 1e9 + 7;
int n;
int m;
int t;
int in[N];
int out[N];
int sum[N];
int d[N][L];
vector<int> g[N];
void dfs(int v, int p) {
  d[v][0] = p;
  in[v] = ++t;
  sum[v] = sum[p] + 1;
  for (int i = 1; i < L; i++) {
    d[v][i] = d[d[v][i - 1]][i - 1];
  }
  for (auto to : g[v]) {
    if (to != p) {
      dfs(to, v);
    }
  }
  out[v] = ++t;
}
int can(int a, int b) { return (in[a] <= in[b] && out[a] >= out[b]); }
int lca(int a, int b) {
  if (can(a, b)) {
    return a;
  }
  if (can(b, a)) {
    return b;
  }
  for (int i = L - 1; i >= 0; i--) {
    if (!can(d[a][i], b)) {
      a = d[a][i];
    }
  }
  return d[a][0];
}
int dist(int a, int b) { return 1 + (sum[a] + sum[b] - 2 * sum[lca(a, b)]); }
int get_max(int s, int t, int f) {
  if (can(f, s) ^ can(f, t)) {
    return 1;
  }
  if (can(f, s) && can(f, t)) {
    return dist(lca(t, s), f);
  }
  if (lca(s, f) == lca(s, f)) {
    return dist(lca(s, t), f);
  }
  return 1 + (sum[f] - max(sum[lca(s, f)], sum[lca(t, f)]));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    g[x].push_back(i + 1);
    g[i + 1].push_back(x);
  }
  dfs(1, 1);
  while (m--) {
    int ans = 0;
    int a, b, c;
    cin >> a >> b >> c;
    ans = max(ans, 1 + (dist(a, b) + dist(a, c) - dist(b, c)) / 2);
    ans = max(ans, 1 + (dist(b, c) + dist(a, b) - dist(a, c)) / 2);
    ans = max(ans, 1 + (dist(b, c) + dist(a, c) - dist(a, b)) / 2);
    cout << ans << endl;
  }
}
