#include <bits/stdc++.h>
inline int read() {
  int data = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
  return data * w;
}
const int N(1e5 + 10), LogN(18);
struct edge {
  int next, to, dis;
} e[N << 1];
int n, Q, head[N], e_num;
inline void add_edge(int from, int to, int dis) {
  e[++e_num] = (edge){head[from], to, dis}, head[from] = e_num;
}
struct Tree {
  int rt, dep[N], mx[N], son[N], fa[LogN][N];
  int top[N], bot[N], id[N], rnk[N], sum[N], c;
  void getDep(int x, int f) {
    for (int i = head[x]; i; i = e[i].next)
      if (e[i].to != f) dep[e[i].to] = dep[x] + e[i].dis, getDep(e[i].to, x);
  }
  void dfs(int x) {
    mx[x] = dep[x];
    for (int i = 1; i < LogN; i++) fa[i][x] = fa[i - 1][fa[i - 1][x]];
    for (int i = head[x]; i; i = e[i].next) {
      int to = e[i].to;
      if (to == fa[0][x]) continue;
      fa[0][to] = x, dep[to] = dep[x] + e[i].dis, dfs(to);
      if (mx[son[x]] < mx[to]) mx[x] = mx[to], son[x] = to;
    }
  }
  void dfs(int x, int tp) {
    top[x] = tp, bot[tp] = x;
    if (son[x]) dfs(son[x], tp);
    for (int i = head[x]; i; i = e[i].next)
      if (e[i].to != fa[0][x] && e[i].to != son[x]) dfs(e[i].to, e[i].to);
  }
  void Init(int s) {
    getDep(s, 0), rt = 0, c = 0;
    for (int i = 1; i <= n; i++)
      if (dep[rt] < dep[i]) rt = i;
    dep[rt] = 0, dfs(rt), dfs(rt, rt);
    for (int i = 1; i <= n; i++)
      if (top[i] == i) id[++c] = i;
    std::sort(id + 1, id + c + 1, [&](int i, int j) {
      return dep[bot[i]] - dep[fa[0][i]] > dep[bot[j]] - dep[fa[0][j]];
    });
    for (int i = 1, x; i <= c; i++) {
      x = bot[id[i]], rnk[top[x]] = i, sum[i] = dep[x] - dep[fa[0][top[x]]];
      for (int b = x; x != top[x]; x = fa[0][x]) rnk[x] = i, bot[x] = b;
    }
    for (int i = 1; i <= c; i++) sum[i] += sum[i - 1];
  }
  int find1(int x, int r) {
    int ans = sum[r] + mx[x];
    for (int i = LogN - 1; ~i; i--)
      if (rnk[fa[i][x]] > r) x = fa[i][x];
    return ans - dep[fa[0][x]];
  }
  int find2(int x, int r) {
    int ans = sum[r] + mx[x];
    for (int i = LogN - 1; ~i; i--)
      if (rnk[fa[i][x]] > r) x = fa[i][x];
    return ans - mx[fa[0][x]];
  }
  int Query(int x, int y) {
    y = (y << 1) - 1;
    if (y >= c) return sum[c];
    if (rnk[x] <= y)
      return sum[y];
    else
      return std::max(find1(x, y - 1), find2(x, y));
  }
} t[2];
int main() {
  n = read(), Q = read();
  for (int i = 1, a, b, c; i < n; i++)
    a = read(), b = read(), c = read(), add_edge(a, b, c), add_edge(b, a, c);
  t[0].Init(1), t[1].Init(t[0].rt);
  for (int x, y, ans = 0; Q--;) {
    x = (read() + ans - 1) % n + 1, y = (read() + ans - 1) % n + 1;
    printf("%d\n", ans = std::max(t[0].Query(x, y), t[1].Query(x, y)));
  }
  return 0;
}
