#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int height[100005], parent[100005][20];
void dfs(int node, int par) {
  parent[node][0] = par;
  for (int i = 1; i < 20; i++)
    parent[node][i] = parent[parent[node][i - 1]][i - 1];
  height[node] = height[par] + 1;
  for (int i = 0; i < v[node].size(); i++) {
    if (v[node][i] == par) continue;
    dfs(v[node][i], node);
  }
}
int findLCA(int node1, int node2) {
  if (height[node1] > height[node2]) swap(node1, node2);
  for (int i = 19; i >= 0; i--) {
    if (height[parent[node2][i]] >= height[node1]) {
      node2 = parent[node2][i];
    }
  }
  if (node1 != node2) {
    for (int i = 19; i >= 0; i--) {
      if (parent[node1][i] != parent[node2][i]) {
        node1 = parent[node1][i];
        node2 = parent[node2][i];
      }
    }
    node1 = parent[node1][0];
    node2 = parent[node2][0];
  }
  return node1;
}
int main() {
  int i, j, k;
  int n, q;
  scanf("%d", &n);
  scanf("%d", &q);
  for (i = 2; i <= n; i++) {
    scanf("%d", &j);
    v[j].push_back(i);
    v[i].push_back(j);
  }
  dfs(1, 0);
  while (q--) {
    scanf("%d", &i);
    scanf("%d", &j);
    scanf("%d", &k);
    int lca1 = findLCA(i, j);
    int lca2 = findLCA(j, k);
    int lca3 = findLCA(i, k);
    int maxheight = max(max(height[lca1], height[lca2]), height[lca3]);
    if (height[lca1] == maxheight) {
      printf("%d\n",
             1 + max(max(height[i] - height[lca1], height[j] - height[lca1]),
                     height[k] - height[lca2] + height[lca1] - height[lca2]));
    } else if (height[lca2] == maxheight) {
      printf("%d\n", 1 + max(max(abs(height[lca2] - height[j]),
                                 abs(height[lca2] - height[k])),
                             abs(height[lca1] - height[i]) +
                                 abs(height[lca1] - height[lca2])));
    } else {
      printf("%d\n", 1 + max(max(abs(height[lca3] - height[i]),
                                 abs(height[lca3] - height[k])),
                             abs(height[lca1] - height[j]) +
                                 abs(height[lca1] - height[lca3])));
    }
  }
  return 0;
}
