#include <bits/stdc++.h>
long long read() {
  long long res = 0, bo = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') bo = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = (res << 1) + (res << 3) + ch - '0';
    ch = getchar();
  }
  return bo * res;
}
template <typename T>
void read(T &x) {
  x = read();
}
template <typename T, typename... Argv>
void read(T &a, Argv &...argv) {
  read(a);
  read(argv...);
}
const int N = 1e5 + 7;
int n, q, k, s, ans;
std::vector<std::pair<int, int> > e[N];
struct T {
  int rt, f[N][21], g[N][21], d[N], dep[N], son[N], top[N], rnk[N];
  int l[N], r[N], s[N], t;
  void dfs1(int x, int fa) {
    for (std::pair<int, int> o : e[x])
      if (o.first != fa) d[o.first] = d[x] + o.second, dfs1(o.first, x);
  }
  void dfs2(int x) {
    for (std::pair<int, int> o : e[x])
      if (o.first != f[x][0]) {
        f[o.first][0] = x, g[o.first][0] = o.second;
        for (int i = 0; f[o.first][i]; i++)
          f[o.first][i + 1] = f[f[o.first][i]][i],
                         g[o.first][i + 1] =
                             g[o.first][i] + g[f[o.first][i]][i];
        d[o.first] = d[x] + o.second, dfs2(o.first);
        if (dep[o.first] + o.second > dep[x])
          dep[x] = dep[o.first] + o.second, son[x] = o.first;
        ;
      }
    for (std::pair<int, int> o : e[x])
      if (o.first != f[x][0] && o.first != son[x])
        s[l[++t] = o.first] = dep[o.first] + o.second;
  }
  void getrt(int x) {
    dfs1(x, 0), rt = x;
    for (int i = 1; i <= n; i++)
      if (d[i] > d[rt]) rt = i;
    d[rt] = 0, dfs2(rt), s[l[++t] = rt] = dep[rt];
    std::sort(l + 1, l + t + 1, [&](int i, int j) { return s[i] > s[j]; });
    for (int i = 1; i <= t; i++) r[i] = r[i - 1] + s[l[i]];
    for (int i = 1; i <= t; i++) {
      int x = l[i], p = x;
      while (x) top[x] = p, rnk[x] = i, x = son[x];
    }
  }
  int ask1(int x, int y) {
    int z = dep[x];
    for (int i = 20; ~i; i--)
      if (rnk[f[x][i]] >= y) z += g[x][i], x = f[x][i];
    return r[y - 1] + z + g[x][0];
  }
  int ask2(int x, int y) {
    int z = dep[x];
    for (int i = 20; ~i; i--)
      if (rnk[f[x][i]] > y) z += g[x][i], x = f[x][i];
    return r[y] - dep[f[x][0]] + z + g[x][0];
  }
  int ask(int x, int y) {
    y = 2 * y - 1;
    return rnk[x] <= y ? r[y] : std::max(ask1(x, y), ask2(x, y));
  }
} t[2];
int main() {
  read(n), read(q);
  for (int i = 1, x, y, z; i < n; i++)
    read(x), read(y), read(z), e[x].push_back(std::pair<int, int>(y, z)),
        e[y].push_back(std::pair<int, int>(x, z)), s += z;
  for (int i = 1; i <= n; i++) k += e[i].size() == 1u;
  t[0].getrt(1), t[1].getrt(t[0].rt);
  for (int i = 1, x, y; i <= q; i++)
    read(x), read(y),
        x = (x + ans - 1) % n + 1, y = (y + ans - 1) % n + 1,
        printf("%d\n",
               ans = 2 * y >= k ? s : std::max(t[0].ask(x, y), t[1].ask(x, y)));
  return 0;
}
