Spiders are Om Nom's old enemies. They love eating candies as much as he does and that's why they keep trying to keep the monster away from his favorite candies. They came up with an evil plan to trap Om Nom.

<image>

Let's consider a rope structure consisting of n nodes and n - 1 ropes connecting the nodes. The structure is connected, thus, the ropes and the nodes form a tree. Each rope of the formed structure is associated with its length. A candy is tied to node x of the structure. Om Nom really wants to eat this candy.

The y spiders are trying to stop him from doing it. They decided to entangle the candy and some part of the structure into a web, thus attaching the candy to as large as possible part of the rope structure. 

Each spider can use his web to cover all ropes on the path between two arbitrary nodes a and b. Thus, y spiders can cover the set of ropes which is a union of y paths in the given tree. These y paths can arbitrarily intersect each other. The spiders want the following conditions to be hold:

  * the node containing the candy is adjacent to at least one rope covered with a web 
  * the ropes covered with the web form a connected structure (what's the idea of covering with a web the ropes that are not connected with the candy?) 
  * the total length of the ropes covered with web is as large as possible 



The spiders haven't yet decided to what node of the structure they will tie the candy and how many spiders will cover the structure with web, so they asked you to help them. Help them calculate the optimal plan for multiple values of x and y.

Input

The first line contains numbers n and q (1 ≤ n, q ≤ 105) — the number of nodes in the structure and the number of questions that the spiders want to ask you.

The next n - 1 lines determine the rope structure. The i-th line contains three integers ui, vi, li (1 ≤ ui, vi ≤ n, ui ≠ vi, 1 ≤ li ≤ 1000), showing that there is a rope of length li between nodes ui and vi.

Next q lines describe the spiders' questions. As they want you to answer their question online, they encoded their messages in a special manner.

Each of the next q lines contains two numbers xi, yi. In the first question of the spiders x = x1, y = y1.

To calculate values x and y in the spiders' i-th (2 ≤ i ≤ q) question, you need to use the following formulas:

<image>

<image>

where Ansi - 1 is the total length of the ropes covered by a web in the answer for the (i - 1)-th question.

The following inequality holds: 1 ≤ xi, yi ≤ n.

Output

For each question of the spiders print on a separate line a single integer Ansi — the total length of the ropes covered with web in the optimal plan.

Examples

Input

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


Output

14
13
17
#include <bits/stdc++.h>
using namespace std;
int n, q, tot, lastans;
const int N = 100005;
int head[N], to[N << 1], nt[N << 1], len[N << 1];
void add(int f, int t, int d) {
  to[++tot] = t;
  len[tot] = d;
  nt[tot] = head[f];
  head[f] = tot;
}
struct SHU {
  int c, root, pos;
  int fa[N][17], dep[N], top[N], maxdep[N], dis[N], son[N], s[N], ans[N],
      col[N], LEN[N];
  vector<int> v[N];
  void dfs0(int u, int pr, int t) {
    if (t) {
      dep[u] = dep[fa[u][0] = pr] + 1;
      for (int j = 0; 2 << j < dep[u]; ++j) fa[u][j + 1] = fa[fa[u][j]][j];
    }
    maxdep[u] = dis[u];
    if (!t && dis[pos] < dis[u]) pos = u;
    for (int i = head[u]; i; i = nt[i])
      if (to[i] != pr) {
        dis[to[i]] = dis[u] + len[i], dfs0(to[i], u, t);
        maxdep[u] = std::max(maxdep[u], maxdep[to[i]]);
        if (t && maxdep[son[u]] < maxdep[to[i]]) son[u] = to[i];
      }
  }
  void dfs1(int u, int t) {
    v[top[u] = t].push_back(u);
    if (son[u]) dfs1(son[u], t);
    for (int i = head[u]; i; i = nt[i])
      if (to[i] != fa[u][0] && to[i] != son[u])
        dfs1(to[i], to[i]), LEN[to[i]] = maxdep[to[i]] - dis[u];
  }
  int YYCH(int x) {
    pos = 0, dis[x] = 0, dfs0(x, 0, 0);
    dis[root = pos] = 0, dfs0(root, 0, 1);
    dfs1(root, root), LEN[root] = maxdep[root];
    for (int i = 1; i <= n; ++i)
      if (top[i] == i) s[++c] = i;
    std::sort(s + 1, s + c + 1, [&](int i, int j) { return LEN[i] > LEN[j]; });
    for (int i = 1; i <= c; ++i) {
      ans[i] = ans[i - 1] + LEN[s[i]];
      for (int u = s[i]; u; u = son[u]) col[u] = i;
    }
    return root;
  }
  inline int plan(int x, int y, int *arr) {
    int u = x;
    for (int j = 16; j >= 0; --j)
      if (col[fa[u][j]] > y) u = fa[u][j];
    u = fa[u][0];
    return ans[y] + maxdep[x] - arr[u];
  }
  inline int ask(int x, int y) {
    y = 2 * y - 1;
    if (y >= c) return ans[c];
    if (col[x] <= y) return ans[y];
    return std::max(plan(x, y - 1, dis), plan(x, y, maxdep));
  }
} T1, T2;
int main() {
  cin >> n >> q;
  for (int i = 1, x, y, z; i < n; ++i)
    scanf("%d%d%d", &x, &y, &z), add(x, y, z), add(y, x, z);
  T2.YYCH(T1.YYCH(1));
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + lastans - 1) % n + 1;
    y = (y + lastans - 1) % n + 1;
    printf("%d\n", lastans = max(T1.ask(x, y), T2.ask(x, y)));
  }
  return 0;
}
