#include <bits/stdc++.h>
using namespace std;
vector<int> e[500000];
long long D[500000];
long long S[500000][19];
int P[500000][19];
int im[500000];
int iM[500000];
void dfs(int x) {
  im[x] = x;
  iM[x] = x;
  for (int i = 0; i < e[x].size(); ++i) {
    int v = e[x][v];
    dfs(v);
    im[x] = min(im[x], im[v]);
    iM[x] = max(iM[x], iM[v]);
  }
}
long long get(int i, int j) {
  int l = j - i + 1;
  int z;
  for (z = 20; z > 0; --z)
    if (l & (1 << z)) break;
  return max(S[i][z], S[i + l - (1 << z)][z]);
}
void solve() {
  int n, q;
  scanf("%d%d", &n, &q);
  P[0][0] = -1;
  for (int i = 1; i < n; ++i) {
    int x, w;
    scanf("%d%d", &x, &w);
    D[i] = D[x - 1] + w;
    P[i][0] = x - 1;
    e[x - 1].push_back(i);
  }
  dfs(0);
  for (int i = 0; i < n; ++i) {
    if (im[i] == i && iM[i] == i)
      S[i][0] = D[i];
    else
      S[i][0] = 1LL << 62;
  }
  for (int j = 0; j < 17; ++j) {
    for (int i = n - (2 << j); i >= 0; --i) {
      S[i][j + 1] = min(S[i][j], S[i + (1 << j)][j]);
    }
  }
  for (int j = 1; j < 19; ++j) {
    for (int i = 0; i < n; ++i) {
      int z = P[i][j - 1];
      if (z == -1)
        P[i][j] = -1;
      else
        P[i][j] = P[z][j - 1];
    }
  }
  for (int i = 0; i < q; ++i) {
    int v, l, r;
    scanf("%d%d%d", &v, &l, &r);
    --v, --l, --r;
    int long long = max(im[v], l);
    int rr = min(iM[v], r);
    printf("%I64d\n", long long <= rr ? get(long long, rr) - D[v] : -1LL);
  }
}
int main() {
  solve();
  return 0;
}
