#include <bits/stdc++.h>
using namespace std;
inline void scale(int x) {
  cout.precision(x);
  cout << fixed;
}
long long lpow(long long x, int y) {
  if (!y) return 1;
  long long t = lpow(x, y / 2);
  if (y & 1) return (y > 0) ? x * t * t : (t * t) / x;
  return t * t;
}
int ipow(int x, int y) {
  if (!y) return 1;
  int t = ipow(x, y / 2);
  if (y & 1) return (y > 0) ? x * t * t : (t * t) / x;
  return t * t;
}
void split(vector<string> &tmp, string &line, char *buffer, char delim = ' ') {
  strcpy(buffer, line.c_str());
  char *token = strtok(buffer, &delim);
  while (token != 0) {
    tmp.emplace_back(string(token));
    token = strtok(NULL, &delim);
  }
}
inline void fastio(int debug) {
  if (debug) {
    cout << "DEBUGGING MODE..." << endl;
    freopen("in", "r", stdin);
  } else {
    ios_base::sync_with_stdio(false), cin.tie(0);
  }
}
bool DRAFT = 0;
int eui = 1;
int lvl[2 * 100005], par[100005], euler[2 * 100005], occ[100005],
    ST[2 * 100005][18];
vector<pair<int, int> > tree[100005];
int n, a, b, c, t, d, p = 2;
void computeSparseTable() {
  for (int i = 1; i <= eui; i++) {
    ST[i][0] = i;
  }
  for (int j = 1; (1 << j) <= eui; j++) {
    for (int i = 1; (i + (1 << j) - 1) <= eui; i++) {
      if (lvl[ST[i][j - 1]] <= lvl[ST[i + (1 << (j - 1))][j - 1]]) {
        ST[i][j] = ST[i][j - 1];
      } else {
        ST[i][j] = ST[i + (1 << (j - 1))][j - 1];
      }
    }
  }
}
int rmq(int a, int b) {
  int k = (int)log2(b - a + 1);
  if (lvl[ST[a][k]] <= lvl[ST[b - (1 << k) + 1][k]]) {
    return ST[a][k];
  } else {
    return ST[b - (1 << k) + 1][k];
  }
}
int LCA(int a, int b) {
  int x = occ[a], y = occ[b];
  if (x > y) swap(x, y);
  return euler[rmq(x, y)];
}
void dfslvl(int cur = 1, int pre = 0, int depth = 1) {
  occ[cur] = eui;
  par[cur] = pre;
  euler[eui] = cur;
  lvl[eui++] = depth;
  vector<pair<int, int> > adj = tree[cur];
  int s1 = (int)adj.size();
  for (int i = 0; i < s1; i++) {
    pair<int, int> pp = adj[i];
    int v = pp.first;
    if (v != pre) {
      dfslvl(v, cur, depth + 1);
      euler[eui] = cur;
      lvl[eui++] = depth;
    }
  }
}
void buildLCATree(int u = 1) {
  dfslvl(u);
  computeSparseTable();
}
int dist(int a, int b) {
  return lvl[occ[a]] + lvl[occ[b]] - 2 * lvl[occ[LCA(a, b)]] + 1;
}
int calc(int a, int b, int c) {
  return (dist(a, b) + dist(b, c) - dist(a, c) + 1) / 2;
}
int main(void) {
  fastio(0);
  cin >> n >> d;
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    tree[p].emplace_back(make_pair(a, 0));
    tree[a].emplace_back(make_pair(p, 0));
    p++;
  }
  buildLCATree(2);
  for (int i = 0; i < d; i++) {
    cin >> a >> b >> c;
    int ans1 = calc(a, b, c);
    int ans2 = calc(b, a, c);
    int ans3 = calc(a, c, b);
    cout << max(ans1, max(ans2, ans3)) << "\n";
  }
  return 0;
}
