#include <bits/stdc++.h>
using namespace std;
namespace red {
inline long long read() {
  long long x = 0;
  char ch, f = 1;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') f = 0, ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return f ? x : -x;
}
const long long N = 3e5 + 10, inf = 0x3f3f3f3f3f3f3f3f;
long long n, m, ans, sum, leave;
long long rd[N];
long long head[N], cnt;
struct point {
  long long nxt, to, val;
  point() {}
  point(const long long &nxt, const long long &to, const long long &val)
      : nxt(nxt), to(to), val(val) {}
} a[N << 1];
inline void link(long long x, long long y, long long z) {
  a[++cnt] = (point){head[x], y, z};
  head[x] = cnt;
  a[++cnt] = (point){head[y], x, z};
  head[y] = cnt;
}
struct tree {
  long long rt, f[N][21], g[N][21], d[N], dep[N], son[N], top[N], rk[N];
  long long l[N], r[N], s[N], tot;
  inline void dfs1(long long now, long long fa) {
    for (long long i = head[now]; i; i = a[i].nxt) {
      long long t = a[i].to;
      if (t == fa) continue;
      d[t] = d[now] + a[i].val;
      dfs1(t, now);
    }
  }
  inline void dfs2(long long now) {
    for (long long i = head[now]; i; i = a[i].nxt) {
      long long t = a[i].to;
      if (t == f[now][0]) continue;
      f[t][0] = now, g[t][0] = a[i].val;
      for (long long j = 1; j <= 20; ++j) {
        f[t][j] = f[f[t][j - 1]][j - 1];
        g[t][j] = g[t][j - 1] + g[f[t][j - 1]][j - 1];
      }
      d[t] = d[now] + a[i].val;
      dfs2(t);
      if (dep[t] + a[i].val > dep[now])
        dep[now] = dep[t] + a[i].val, son[now] = t;
    }
    for (long long i = head[now]; i; i = a[i].nxt) {
      long long t = a[i].to;
      if (t == f[now][0] || t == son[now]) continue;
      s[l[++tot] = t] = dep[t] + a[i].val;
    }
  }
  inline void getrt(long long now) {
    dfs1(now, 0);
    rt = now;
    for (long long i = 1; i <= n; ++i)
      if (d[i] > d[rt]) rt = i;
    d[rt] = 0;
    dfs2(rt);
    s[l[++tot] = rt] = dep[rt];
    sort(l + 1, l + tot + 1,
         [&](long long i, long long j) { return s[i] > s[j]; });
    for (long long i = 1; i <= tot; ++i) r[i] = r[i - 1] + s[l[i]];
    for (long long i = 1; i <= tot; ++i) {
      long long x = l[i], p = x;
      while (x) top[x] = p, rk[x] = i, x = son[x];
    }
  }
  inline long long solve1(long long x, long long y) {
    long long z = dep[x];
    for (long long i = 20; ~i; --i)
      if (rk[f[x][i]] >= y) z += g[x][i], x = f[x][i];
    return r[y - 1] + z + g[x][0];
  }
  inline long long solve2(long long x, long long y) {
    long long z = dep[x];
    for (long long i = 20; ~i; --i)
      if (rk[f[x][i]] > y) z += g[x][i], x = f[x][i];
    return r[y] - dep[f[x][0]] + z + g[x][0];
  }
  inline long long ask(long long x, long long y) {
    y = 2 * y - 1;
    return rk[x] <= y ? r[y] : max(solve1(x, y), solve2(x, y));
  }
} t[2];
inline void main() {
  n = read(), m = read();
  for (long long x, y, z, i = 1; i < n; ++i) {
    x = read(), y = read(), z = read();
    ++rd[x], ++rd[y];
    link(x, y, z);
    sum += z;
  }
  for (long long i = 1; i <= n; ++i) leave += (rd[i] == 1);
  t[0].getrt(1), t[1].getrt(t[0].rt);
  for (long long x, y, i = 1; i <= m; ++i) {
    x = read(), y = read();
    x = (x + ans - 1) % n + 1, y = (y + ans - 1) % n + 1;
    printf("%lld\n",
           ans = 2 * y >= leave ? sum : max(t[0].ask(x, y), t[1].ask(x, y)));
  }
}
}  // namespace red
signed main() {
  red::main();
  return 0;
}
