#include <bits/stdc++.h>
using namespace std;
void initialize(int start, vector<int>& stree, vector<int>& level, int l,
                int u) {
  if (int((stree).size()) - 1 < start) stree.resize(start + 1);
  if (l == u)
    stree[start] = l;
  else {
    initialize(2 * start, stree, level, l, (u + l) / 2);
    initialize(2 * start + 1, stree, level, (u + l) / 2 + 1, u);
    if (level[stree[start * 2]] < level[stree[start * 2 + 1]])
      stree[start] = stree[start * 2];
    else
      stree[start] = stree[start * 2 + 1];
  }
  return;
}
int rmq(int start, vector<int>& stree, vector<int>& level, int i, int j, int l,
        int u) {
  if (j < l || i > u) return -1;
  if (l >= i && u <= j) return stree[start];
  int t1 = rmq(2 * start, stree, level, i, j, l, (u + l) / 2);
  int t2 = rmq(2 * start + 1, stree, level, i, j, (u + l) / 2 + 1, u);
  if (t1 == -1) return t2;
  if (t2 == -1) return t1;
  if (level[t1] < level[t2]) return t1;
  return t2;
}
void dfs(vector<vector<int> >& alist, vector<int>& tour, int root,
         vector<int>& entry, vector<int>& level, vector<int>& visited,
         int currentlevel) {
  visited[root] = 1;
  tour.push_back(root);
  level.push_back(currentlevel);
  entry[root] = int((tour).size()) - 1;
  for (int i = 0; i <= int((alist[root]).size()) - 1; i++) {
    if (!visited[alist[root][i]]) {
      dfs(alist, tour, alist[root][i], entry, level, visited, currentlevel + 1);
      tour.push_back(root);
      level.push_back(currentlevel);
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<vector<int> > alist(n + 1);
  int p;
  for (int i = 2; i <= n; i++) {
    cin >> p;
    alist[i].push_back(p);
    alist[p].push_back(i);
  }
  vector<int> tour, level, entry(n + 1), visited(n + 1, 0), stree;
  dfs(alist, tour, 1, entry, level, visited, 0);
  initialize(1, stree, level, 0, int((level).size()) - 1);
  int a, b, c, ab, ac, bc, lab, lac, lbc, la, lb, lc;
  for (int query = 1; query <= q; query++) {
    cin >> a >> b >> c;
    ab = tour[rmq(1, stree, level, min(entry[a], entry[b]),
                  max(entry[a], entry[b]), 0, int((level).size()) - 1)];
    ac = tour[rmq(1, stree, level, min(entry[a], entry[c]),
                  max(entry[a], entry[c]), 0, int((level).size()) - 1)];
    bc = tour[rmq(1, stree, level, min(entry[c], entry[b]),
                  max(entry[c], entry[b]), 0, int((level).size()) - 1)];
    lab = level[entry[a]] + level[entry[b]] - level[entry[ab]] * 2;
    lac = level[entry[a]] + level[entry[c]] - level[entry[ac]] * 2;
    lbc = level[entry[b]] + level[entry[c]] - level[entry[bc]] * 2;
    la = (lab + lac - lbc) / 2;
    lb = (lab + lbc - lac) / 2;
    lc = (lbc + lac - lab) / 2;
    cout << max(la, max(lb, lc)) + 1 << '\n';
  }
  return 0;
}
