Let's define the Eulerian traversal of a tree (a connected undirected graph without cycles) as follows: consider a depth-first search algorithm which traverses vertices of the tree and enumerates them in the order of visiting (only the first visit of each vertex counts). This function starts from the vertex number 1 and then recursively runs from all vertices which are connected with an edge with the current vertex and are not yet visited in increasing numbers order. Formally, you can describe this function using the following pseudocode:
    
    
      
    next_id = 1  
    id = array of length n filled with -1  
    visited = array of length n filled with false  
      
    function dfs(v):  
        visited[v] = true  
        id[v] = next_id  
        next_id += 1  
        for to in neighbors of v in increasing order:  
            if not visited[to]:  
                dfs(to)  
    

You are given a weighted tree, the vertices of which were enumerated with integers from 1 to n using the algorithm described above.

A leaf is a vertex of the tree which is connected with only one other vertex. In the tree given to you, the vertex 1 is not a leaf. The distance between two vertices in the tree is the sum of weights of the edges on the simple path between them.

You have to answer q queries of the following type: given integers v, l and r, find the shortest distance from vertex v to one of the leaves with indices from l to r inclusive. 

Input

The first line contains two integers n and q (3 ≤ n ≤ 500 000, 1 ≤ q ≤ 500 000) — the number of vertices in the tree and the number of queries, respectively.

The (i - 1)-th of the following n - 1 lines contains two integers p_i and w_i (1 ≤ p_i < i, 1 ≤ w_i ≤ 10^9), denoting an edge between vertices p_i and i with the weight w_i.

It's guaranteed that the given edges form a tree and the vertices are enumerated in the Eulerian traversal order and that the vertex with index 1 is not a leaf.

The next q lines describe the queries. Each of them contains three integers v_i, l_i, r_i (1 ≤ v_i ≤ n, 1 ≤ l_i ≤ r_i ≤ n), describing the parameters of the query. It is guaranteed that there is at least one leaf with index x such that l_i ≤ x ≤ r_i.

Output

Output q integers — the answers for the queries in the order they are given in the input.

Examples

Input


5 3
1 10
1 1
3 2
3 3
1 1 5
5 4 5
4 1 2


Output


3
0
13


Input


5 3
1 1000000000
2 1000000000
1 1000000000
1 1000000000
3 4 5
2 1 5
2 4 5


Output


3000000000
1000000000
2000000000


Input


11 8
1 7
2 1
1 20
1 2
5 6
6 2
6 3
5 1
9 10
9 11
5 1 11
1 1 4
9 4 8
6 1 4
9 7 11
9 10 11
8 1 11
11 4 5


Output


8
8
9
16
9
10
0
34

Note

In the first example, the tree looks like this: 

<image>

In the first query, the nearest leaf for the vertex 1 is vertex 4 with distance 3. In the second query, the nearest leaf for vertex 5 is vertex 5 with distance 0. In the third query the nearest leaf for vertex 4 is vertex 4; however, it is not inside interval [1, 2] of the query. The only leaf in interval [1, 2] is vertex 2 with distance 13 from vertex 4.
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, M = 22;
const long long INF = 1e18;
int n, m;
int p[N], d[N];
bool used[N];
int step[N];
long long dp[M][N];
long long dist[M][N], ans[N];
vector<pair<int, long long> > q[N];
vector<pair<int, int> > g[N];
vector<pair<pair<int, long long>, pair<int, int> > > f[N];
int dfs(int v, int size, int &center, int pr = -1) {
  int sz = 1;
  for (auto it : g[v]) {
    int to = it.first;
    if (to != pr && !used[to]) {
      sz += dfs(to, size, center, v);
    }
  }
  if (center == -1 && sz >= size / 2) {
    center = v;
  }
  return sz;
}
void dfs1(int v, int depth, int pr = -1, long long len = 0) {
  dist[depth][v] = len;
  for (auto it : g[v]) {
    int to = it.first, val = it.second;
    if (to != pr && !used[to]) {
      dfs1(to, depth, v, len + val);
    }
  }
}
void build(int v, int pr = -1, int depth = 0) {
  int center = -1, tmp = 0;
  dfs(v, dfs(v, 0, tmp), center);
  dfs1(center, depth);
  used[center] = true;
  d[center] = depth;
  p[center] = pr;
  for (auto it : g[center]) {
    int to = it.first;
    if (!used[to]) {
      build(to, center, depth + 1);
    }
  }
}
inline long long get_min(int l, int r) {
  int x = step[r - l + 1];
  return min(dp[x][l], dp[x][r - (1 << x) + 1]);
}
int main() {
  srand(time(nullptr));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i < N; i++) {
    step[i] = step[i >> 1] + 1;
  }
  cin >> n >> m;
  for (int i = 2; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(make_pair(i, y));
    g[i].push_back(make_pair(x, y));
  }
  build(1);
  for (int i = 2; i <= n; i++) {
    if ((int)g[i].size() == 1) {
      int cur = i;
      while (cur != -1) {
        q[cur].push_back(make_pair(i, dist[d[cur]][i]));
        cur = p[cur];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(q[i].begin(), q[i].end());
  }
  for (int i = 1; i <= m; i++) {
    int v, l, r;
    cin >> v >> l >> r;
    ans[i] = INF;
    int cur = v;
    while (cur != -1) {
      if (!q[cur].empty()) {
        int tl = lower_bound(q[cur].begin(), q[cur].end(), make_pair(l, -1LL)) -
                 q[cur].begin(),
            tr = lower_bound(q[cur].begin(), q[cur].end(),
                             make_pair(r + 1, -1LL)) -
                 q[cur].begin() - 1;
        if (tl <= tr) {
          f[cur].push_back(make_pair(make_pair(i, dist[d[cur]][v]),
                                     make_pair(tl + 1, tr + 1)));
        }
      }
      cur = p[cur];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!q[i].empty()) {
      int sz = (int)q[i].size();
      for (int j = 1; j <= sz; j++) {
        dp[0][j] = q[i][j - 1].second;
      }
      for (int j = 1; j <= step[sz]; j++) {
        for (int k = 1; k + (1 << j) - 1 <= sz; k++) {
          dp[j][k] = min(dp[j - 1][k], dp[j - 1][k + (1 << (j - 1))]);
        }
      }
      for (auto it : f[i]) {
        ans[it.first.first] =
            min(ans[it.first.first],
                it.first.second + get_min(it.second.first, it.second.second));
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << "\n";
  }
}
