#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  itval(++it, args...);
}
const long long int MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {
  cout << x << "\n";
}
template <typename T>
inline void printvec(T x) {
  for (auto a : x) cout << a << ' ';
  cout << '\n';
}
struct custom {
  bool operator()(
      const pair<long long int, pair<long long int, long long int> > &p1,
      const pair<long long int, pair<long long int, long long int> > &p2)
      const {
    return p1.second.second < p2.second.second;
  }
};
long long int get_pow(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
const long long int N = 1e3 + 4, inf = 4e18;
struct LCA {
 public:
  std::vector<vector<int> > adj;
  vector<int> first, euler_tour, height, seg, par, tin, tout;
  int tim = 0;
  void init(int n) {
    adj.resize(n);
    height.resize(n);
    first.resize(n);
    seg.resize(8 * n);
    par.resize(n);
    tin.resize(n);
    tout.resize(n);
  }
  void dfs(int s, int p, int h) {
    tin[s] = tim++;
    height[s] = h;
    par[s] = p;
    euler_tour.push_back(s);
    first[s] = euler_tour.size() - 1;
    for (auto x : adj[s]) {
      if (x != p) {
        dfs(x, s, h + 1);
        euler_tour.push_back(s);
      }
    }
    tout[s] = tim++;
  }
  int _merge(int a, int b) {
    if (a == -1) {
      return b;
    }
    if (b == -1) {
      return a;
    }
    if (height[a] < height[b])
      return a;
    else
      return b;
  }
  void _build_segtree(int node, int lx, int rx) {
    if (rx == lx) {
      seg[node] = euler_tour[lx];
      return;
    }
    int mid = (lx + rx) / 2;
    _build_segtree(2 * node + 1, lx, mid);
    _build_segtree(2 * node + 2, mid + 1, rx);
    seg[node] = _merge(seg[2 * node + 1], seg[2 * node + 2]);
  }
  int _query(int node, int lx, int rx, int req_l, int req_r) {
    if (req_r < lx || rx < req_l) {
      return -1;
    }
    if (req_l <= lx && rx <= req_r) {
      return seg[node];
    }
    int mid = (lx + rx) / 2;
    int p1 = _query(2 * node + 1, lx, mid, req_l, req_r);
    int p2 = _query(2 * node + 2, mid + 1, rx, req_l, req_r);
    return _merge(p1, p2);
  }
  int query(int req_l, int req_r) {
    return _query(0, 0, euler_tour.size() - 1, req_l, req_r);
  }
  void preprocess(int root) {
    dfs(root, -1, 0);
    _build_segtree(0, 0, euler_tour.size() - 1);
  }
  int find_lca(int u, int v) {
    int h1 = first[u], h2 = first[v];
    if (h1 > h2) swap(h2, h1);
    return query(h1, h2);
  }
  int distance(int u, int v) { return abs(height[u] - height[v]) + 1; }
  int fdistance(int u, int v) {
    return height[u] + height[v] - 2 * height[find_lca(u, v)] + 1;
  }
  bool check(int a, int b, int c) {
    bool o = (tin[a] <= tin[b] && tout[a] >= tout[b]);
    bool e = (tin[b] <= tin[c] && tout[b] >= tout[c]);
    bool t = (tin[a] <= tin[c] && tout[a] >= tout[c]);
    bool s = (tin[c] <= tin[b] && tout[c] >= tout[b]);
    return (o && e) || (t && s);
  }
};
void solve() {
  int n, q, x;
  cin >> n >> q;
  LCA lca;
  lca.init(n);
  for (long long int i = (long long int)1; i < (long long int)(n); i++) {
    cin >> x;
    x--;
    lca.adj[x].push_back(i);
    lca.adj[i].push_back(x);
  }
  lca.preprocess(0);
  int a, b, c, d1, d2, d3, u1, u2, u3;
  for (long long int i = (long long int)0; i < (long long int)(q); i++) {
    cin >> a >> b >> c;
    a--;
    b--;
    c--;
    if (a == b && b == c) {
      cout << 1 << '\n';
      continue;
    }
    if (a == b) {
      cout << lca.fdistance(a, c) << '\n';
      continue;
    }
    if (b == c) {
      cout << lca.fdistance(a, c) << '\n';
      continue;
    }
    if (a == c) {
      cout << lca.fdistance(b, c) << '\n';
      continue;
    }
    vector<int> v = {a, b, c};
    sort(v.begin(), v.end());
    int ans = 0, cur;
    do {
      cur = 1 + (lca.fdistance(v[0], v[1]) + lca.fdistance(v[1], v[2]) -
                 lca.fdistance(v[0], v[2])) /
                    2;
      ans = max(ans, cur);
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  clock_t z = clock();
  for (long long int tes = (long long int)0; tes < (long long int)(test);
       tes++) {
    solve();
  }
  fprintf(stderr, "Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
  return 0;
}
