#include <bits/stdc++.h>
using namespace std;
vector<int> G[100029];
int par[100029][17];
int h[100029];
void dfs(int v = 0) {
  for (int i = 1; i < 17; i++) {
    par[v][i] = par[par[v][i - 1]][i - 1];
  }
  for (int neigh : G[v]) {
    h[neigh] = h[v] + 1;
    par[neigh][0] = v;
    dfs(neigh);
  }
}
int lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = 0; i < 17; i++)
    if (h[u] - h[v] >> i & 1) v = par[v][i];
  if (v == u) return v;
  for (int i = 17 - 1; i >= 0; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return v == u ? v : par[v][0];
}
int calc(int f, int s, int t) {
  int ans = 0;
  bool is1 = lca(f, s) == f;
  bool is2 = lca(f, t) == f;
  if (is1 != is2) return 1;
  if (is1)
    ans = max(ans, h[lca(s, t)] - h[f]);
  else if (lca(f, s) != lca(f, t))
    ans = max(ans, h[f] - max(h[lca(f, s)], h[lca(f, t)]));
  else
    ans = max(ans, h[f] + h[lca(s, t)] - 2 * h[lca(f, t)]);
  return ans + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, q;
  cin >> n >> q;
  int a;
  for (int i = 1; i < n; i++) {
    cin >> a;
    a--;
    G[a].push_back(i);
  }
  dfs();
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    a--, b--, c--;
    cout << max(max(calc(a, b, c), calc(b, a, c)), calc(c, b, a)) << endl;
  }
  return 0;
}
