#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T& a, const T& b) {
  return a < b ? (a = b, true) : false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  return b < a ? (a = b, true) : false;
}
int N, Q;
const int M = 3;
const int MAX_N = 100000;
vector<int> G[MAX_N];
int depth[MAX_N], par[20][MAX_N];
void dfs(int curr, int prev = -1) {
  if (prev == -1) {
    depth[curr] = 0;
  } else {
    depth[curr] = depth[prev] + 1;
  }
  for (const auto& it : G[curr])
    if (it != prev) {
      par[0][it] = curr;
      dfs(it, curr);
    }
}
void init() {
  memset(par, -1, sizeof(par));
  dfs(0);
  for (int i = (int)(1); i < (int)(20); i++)
    for (int j = (int)(0); j < (int)(N); j++)
      if (par[i - 1][j] != -1) {
        par[i][j] = par[i - 1][par[i - 1][j]];
      }
}
int lca(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if (par[i][x] != -1 && depth[par[i][x]] >= depth[y]) {
      x = par[i][x];
    }
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (par[i][x] != -1 && par[i][y] != -1 && par[i][x] != par[i][y]) {
      x = par[i][x];
      y = par[i][y];
    }
  return par[0][x];
}
int main() {
  scanf("%d%d", &N, &Q);
  for (int i = (int)(1); i < (int)(N); i++) {
    int u;
    scanf("%d", &u);
    u--;
    G[i].push_back(u);
    G[u].push_back(i);
  }
  init();
  for (int i = (int)(0); i < (int)(Q); i++) {
    int A[M];
    for (int j = (int)(0); j < (int)(M); j++) {
      scanf("%d", &A[j]);
      A[j]--;
    }
    sort(A, A + M);
    int ans = 0;
    do {
      int x = lca(A[0], A[1]), y = lca(A[1], A[2]), z = lca(A[2], A[0]);
      if (depth[x] >= max(depth[y], depth[z])) {
        chmax(ans, depth[A[2]] + depth[x] - max(depth[y], depth[z]) * 2 + 1);
      } else {
        chmax(ans, depth[A[2]] - max(depth[y], depth[z]) + 1);
      }
    } while (next_permutation(A, A + M));
    printf("%d\n", ans);
  }
  return 0;
}
