#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int LogN = 21;
int n, q, all, leaf;
struct Edge {
  int to, val;
};
vector<Edge> G[N];
template <typename _Tp>
inline void IN(_Tp& x) {
  char ch;
  bool flag = 0;
  x = 0;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-') flag = 1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  if (flag) x = -x;
}
inline void addedge(int u = 0, int v = 0, int w = 0) {
  IN(u), IN(v), IN(w), all += w;
  G[u].push_back((Edge){v, w}), G[v].push_back((Edge){u, w});
}
struct T {
  int rt, f[N][21], g[N][21], dis[N], mx[N], son[N], top[N], rank[N];
  int nod[N], sum[N], val[N], m;
  void dfs1(int x, int fa) {
    for (Edge o : G[x])
      if (o.to != fa) dis[o.to] = dis[x] + o.val, dfs1(o.to, x);
  }
  void dfs2(int x) {
    for (Edge o : G[x])
      if (o.to != f[x][0]) {
        f[o.to][0] = x, g[o.to][0] = o.val;
        for (int i = 0; f[o.to][i]; i++)
          f[o.to][i + 1] = f[f[o.to][i]][i],
                      g[o.to][i + 1] = g[o.to][i] + g[f[o.to][i]][i];
        dis[o.to] = dis[x] + o.val, dfs2(o.to);
        if (mx[o.to] + o.val > mx[x]) mx[x] = mx[o.to] + o.val, son[x] = o.to;
        ;
      }
    for (Edge o : G[x])
      if (o.to != f[x][0] && o.to != son[x])
        val[nod[++m] = o.to] = mx[o.to] + o.val;
  }
  void getroot(int x) {
    dfs1(x, 0), rt = x;
    for (int i = 1; i <= n; i++)
      if (dis[i] > dis[rt]) rt = i;
    dis[rt] = 0, dfs2(rt), val[nod[++m] = rt] = mx[rt];
    sort(nod + 1, nod + m + 1, [&](int i, int j) { return val[i] > val[j]; });
    for (int i = 1; i <= m; i++) sum[i] = sum[i - 1] + val[nod[i]];
    for (int i = 1; i <= m; i++) {
      int x = nod[i], p = x;
      while (x) top[x] = p, rank[x] = i, x = son[x];
    }
  }
  inline int plan1(int x, int y) {
    int z = mx[x];
    for (int i = 20; ~i; i--)
      if (rank[f[x][i]] >= y) z += g[x][i], x = f[x][i];
    return sum[y - 1] + z + g[x][0];
  }
  inline int plan2(int x, int y) {
    int z = mx[x];
    for (int i = 20; ~i; i--)
      if (rank[f[x][i]] > y) z += g[x][i], x = f[x][i];
    return sum[y] - mx[f[x][0]] + z + g[x][0];
  }
  inline int query(int x, int y) {
    y = 2 * y - 1;
    return rank[x] <= y ? sum[y] : max(plan1(x, y), plan2(x, y));
  }
} T1, T2;
int main() {
  IN(n), IN(q);
  for (int i = 2; i <= n; ++i) addedge();
  for (int i = 1; i <= n; ++i) leaf += (int)(G[i].size()) == 1;
  T1.getroot(1), T2.getroot(T1.rt);
  int x, y, lastans = 0;
  while (q--) {
    IN(x), IN(y);
    x = (x + lastans - 1) % n + 1, y = (y + lastans - 1) % n + 1;
    printf("%d\n",
           lastans =
               ((y << 1) >= leaf ? all : max(T1.query(x, y), T2.query(x, y))));
  }
  return 0;
}
