#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-10;
const long long MOD = 1e9 + 7;
const long double PI = 3.1415926535897932384626433832795028841;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
using namespace std;
int gv(int i, int j, int col_size) { return i * col_size + j; }
int log(int x) { return 32 - __builtin_clz(x) - 1; }
template <class T>
struct rmq_sparse_table {
  T *rmq_val, *rmq_index;
  int *pw2;
  bool (*cmp_fun)(T a, T b);
  int sz_max, cnt_el, col_size;
  rmq_sparse_table() {}
  rmq_sparse_table(T *arr, int n, int cols, bool (*cmp)(T a, T b)) {
    col_size = cols;
    rmq_val = new T[n * cols];
    rmq_index = new T[n * cols];
    pw2 = new int[cols];
    for (int i = 0; i < n; i++) {
      rmq_val[gv(i, 0, col_size)] = arr[i];
      rmq_index[gv(i, 0, col_size)] = i;
    }
    T pow2 = 2;
    pw2[0] = 1;
    sz_max = 0;
    cnt_el = n;
    cmp_fun = cmp;
    for (int sz = 1; pow2 <= n; sz++, pow2 *= 2) {
      for (int i = 0; i + pow2 <= n; i++) {
        if (cmp(rmq_val[gv(i, sz - 1, col_size)],
                rmq_val[gv(i + pow2 / 2, sz - 1, col_size)])) {
          rmq_val[gv(i, sz, col_size)] = rmq_val[gv(i, sz - 1, col_size)];
          rmq_index[gv(i, sz, col_size)] = rmq_index[gv(i, sz - 1, col_size)];
        } else {
          rmq_val[gv(i, sz, col_size)] =
              rmq_val[gv(i + pow2 / 2, sz - 1, col_size)];
          rmq_index[gv(i, sz, col_size)] =
              rmq_index[gv(i + pow2 / 2, sz - 1, col_size)];
        }
      }
      pw2[sz] = pow2;
      sz_max = max(sz_max, sz);
    }
  }
  pair<int, T> query(int l, int r) {
    int sz = log(r - l + 1);
    if (cmp_fun(rmq_val[gv(l, sz, col_size)],
                rmq_val[gv(r - pw2[sz] + 1, sz, col_size)])) {
      return pair<int, T>(rmq_index[gv(l, sz, col_size)],
                          rmq_val[gv(l, sz, col_size)]);
    } else {
      return pair<int, T>(rmq_index[gv(r - pw2[sz] + 1, sz, col_size)],
                          rmq_val[gv(r - pw2[sz] + 1, sz, col_size)]);
    }
  }
  void show_arr() {}
  ~rmq_sparse_table() {
    delete[] rmq_val;
    delete[] rmq_index;
    delete[] pw2;
  }
};
struct trip_data_t {
  int *V, *L, *D, *Fvst, cnt_vst;
  trip_data_t() {}
  trip_data_t(int n) {
    cnt_vst = 0;
    Fvst = new int[n + 10];
    D = new int[n + 10];
    L = new int[n * 2 + 10];
    V = new int[n * 2 + 10];
    fill(Fvst, Fvst + n + 1, -1);
  }
  void register_node(int i, int depth) {
    V[cnt_vst] = i;
    L[cnt_vst] = depth;
    D[i] = depth;
    if (Fvst[i] == -1) {
      Fvst[i] = cnt_vst;
    }
    cnt_vst++;
  }
  void show_trip() {
    printf("Trip data: \n");
    for (int i = 0; i < cnt_vst; i++) {
      printf("%d (%d) - ", V[i], L[i]);
    }
    printf("\n");
  }
  ~trip_data_t() {
    delete[] L;
    delete[] V;
    delete[] D;
    delete[] Fvst;
  }
};
void dfs(int parent, int i, vector<int> *E, trip_data_t *data, int depth) {
  data->register_node(i, depth);
  for (int j = 0; j < E[i].size(); j++) {
    if (E[i][j] == parent) continue;
    dfs(i, E[i][j], E, data, depth + 1);
    data->register_node(i, depth);
  }
}
bool cmp_min(int a, int b) { return a < b; }
struct lca_computer_t {
  rmq_sparse_table<int> *table;
  trip_data_t *trip_data;
  lca_computer_t() {}
  lca_computer_t(int n, int root, vector<int> *E) {
    trip_data = new trip_data_t(n);
    dfs(-1, root, E, trip_data, 1);
    table = new rmq_sparse_table<int>(trip_data->L, trip_data->cnt_vst, 20,
                                      cmp_min);
  }
  pair<int, int> compute_lca(int i, int j) {
    int a = min(trip_data->Fvst[i], trip_data->Fvst[j]);
    int b = max(trip_data->Fvst[i], trip_data->Fvst[j]);
    pair<int, int> ans = table->query(a, b);
    return pair<int, int>(trip_data->V[ans.first], ans.second);
  }
  int compute_dist(int i, int j) {
    return trip_data->D[i] + trip_data->D[j] - 2 * compute_lca(i, j).second + 1;
  }
  ~lca_computer_t() {
    delete trip_data;
    delete table;
  }
  int get_depth(int i) { return trip_data->D[i]; }
};
const int maxn = 1e5 + 20;
vector<int> edges[maxn];
lca_computer_t *lca_computer;
int dst(int a, int b) { return lca_computer->compute_dist(a, b); }
int try_on(int s, int t, int f) {
  return (dst(s, f) + dst(t, f) - dst(s, t) + 1) / 2;
}
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int j;
    cin >> j;
    edges[i].push_back(j);
    edges[j].push_back(i);
  }
  lca_computer = new lca_computer_t(n, 1, edges);
  for (int i = 0; i < q; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    ans = max(ans, try_on(a, b, c));
    ans = max(ans, try_on(a, c, b));
    ans = max(ans, try_on(b, c, a));
    printf("%d \n", ans);
  }
  delete lca_computer;
}
