#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0;
  register char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return x;
}
const int N = 1e5 + 5;
const int M = 2e5 + 5;
int n, m, ans, now, v[M], w[M], nex[M], head[N];
struct each {
  int rt, cnt, dep[N], top[N], son[N], sum[N], deep[N], fa[N][20];
  void dfs(int x) {
    for (int i = 1; i < 20; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
    for (int i = head[x]; i; i = nex[i]) {
      if (v[i] != fa[x][0]) {
        fa[v[i]][0] = x, dep[v[i]] = dep[x] + w[i];
        dfs(v[i]), deep[v[i]] += w[i];
        if (deep[x] < deep[v[i]]) {
          deep[x] = deep[v[i]];
          son[x] = v[i];
        }
      }
    }
  }
  void dfs(int x, int t) {
    top[x] = t;
    if (son[x]) dfs(son[x], t);
    for (int i = head[x]; i; i = nex[i])
      if (!top[v[i]]) dfs(v[i], v[i]);
  }
  int id[N], rk[N], g[N][20];
  void Dfs(int x) {
    for (int i = 1; i < 20; i++)
      g[x][i] = min(g[x][i - 1], g[fa[x][i - 1]][i - 1]);
    for (int i = head[x]; i; i = nex[i])
      if (v[i] != fa[x][0]) g[v[i]][0] = rk[top[x]], Dfs(v[i]);
  }
  bool com(int x, int y) { return deep[x] > deep[y]; }
  void pre() {
    for (int i = 1; i <= n; i++) id[i] = i;
    dfs(rt), dfs(rt, rt);
    sort(id + 1, id + n + 1, [&](int i, int j) { return deep[i] > deep[j]; });
    for (int i = 1; i <= n; i++)
      if (top[id[i]] == id[i]) {
        rk[id[i]] = ++cnt;
        sum[cnt] = sum[cnt - 1] + deep[id[i]];
      }
    Dfs(rt);
  }
  int find(int x, int y) {
    for (int i = 19; ~i; i--)
      if (g[x][i] > y) x = fa[x][i];
    return x;
  }
  int ask(int x, int y) {
    if (rk[top[x]] <= y) return sum[min(cnt, y)];
    int k = fa[find(x, y)][0];
    return sum[y] - min(deep[son[k]], sum[y] - sum[y - 1]) + deep[top[x]] +
           dep[fa[top[x]][0]] - dep[k];
  }
} t[2];
void addedges(int x, int y, int z) {
  nex[++now] = head[x], w[now] = z;
  head[x] = now, v[now] = y;
}
int _max, r1, r2, vm[N], mx[N], cx[N], vc[N];
void dfs(int x, int fa) {
  vm[x] = x;
  for (int i = head[x]; i; i = nex[i])
    if (v[i] != fa) {
      dfs(v[i], x);
      if (mx[x] < mx[v[i]] + w[i])
        cx[x] = mx[x], vc[x] = vm[x], mx[x] = mx[v[i]] + w[i], vm[x] = vm[v[i]];
      else if (mx[v[i]] + w[i] > cx[x])
        cx[x] = mx[v[i]] + w[i], vc[x] = vm[v[i]];
    }
  if (mx[x] + cx[x] > _max) {
    _max = mx[x] + cx[x];
    t[0].rt = vm[x], t[1].rt = vc[x];
  }
}
int main() {
  n = read(), m = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read(), z = read();
    addedges(x, y, z), addedges(y, x, z);
  }
  dfs(1, 1), t[0].pre(), t[1].pre();
  while (m--) {
    int x = (read() + ans - 1) % n + 1,
        y = ((read() + ans - 1) % n + 1) * 2 - 1;
    ans = max(t[0].ask(x, y), t[1].ask(x, y));
    printf("%d\n", ans);
  }
  return 0;
}
