#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n, q, A, B, l, tot, sum, head[N], v[N << 1], nxt[N << 1], w[N << 1], mxl[N],
    mxp[N];
void add(int x, int y, int s) {
  v[++tot] = y;
  w[tot] = s;
  nxt[tot] = head[x];
  head[x] = tot;
}
void dfs(int u, int fa) {
  mxp[u] = u;
  for (int i = head[u]; ~i; i = nxt[i]) {
    if (v[i] != fa) {
      dfs(v[i], u);
      if (mxl[u] + mxl[v[i]] + w[i] > l) {
        l = mxl[u] + mxl[v[i]] + w[i];
        A = mxp[u];
        B = mxp[v[i]];
      }
      if (mxl[v[i]] + w[i] > mxl[u]) {
        mxl[u] = mxl[v[i]] + w[i];
        mxp[u] = mxp[v[i]];
      }
    }
  }
}
struct tree {
  int cnt, dep[N], rdep[N], lf[N], son[N], tp[N], od[N], minm[N], fa[N][17],
      pos[N], num[N];
  pair<int, int> val[N];
  void dfs1(int u) {
    for (int i = 1; i <= 16; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
    lf[u] = u;
    for (int i = head[u]; ~i; i = nxt[i]) {
      if (v[i] != fa[u][0]) {
        fa[v[i]][0] = u;
        dep[v[i]] = dep[u] + w[i];
        rdep[v[i]] = rdep[u] + 1;
        dfs1(v[i]);
        if (dep[lf[v[i]]] - dep[u] > dep[lf[u]] - dep[u]) {
          lf[u] = lf[v[i]];
          son[u] = v[i];
        }
      }
    }
  }
  void dfs2(int u, int t) {
    tp[u] = t;
    if (son[u]) dfs2(son[u], t);
    for (int i = head[u]; ~i; i = nxt[i])
      if (v[i] != son[u] && v[i] != fa[u][0]) dfs2(v[i], v[i]);
  }
  void dfs3(int u) {
    minm[u] = od[lf[u]];
    for (int i = head[u]; ~i; i = nxt[i]) {
      if (v[i] != fa[u][0]) {
        dfs3(v[i]);
        minm[u] = min(minm[u], minm[v[i]]);
      }
    }
  }
  inline int gval(int i) { return dep[i] - dep[fa[tp[i]][0]]; }
  void work(int A) {
    dfs1(A);
    dfs2(A, A);
    for (int i = 1; i <= n; i++)
      if (lf[i] == i) val[++cnt] = make_pair(gval(i), i);
    sort(val + 1, val + cnt + 1);
    reverse(val + 1, val + cnt + 1);
    for (int i = 1; i <= cnt; i++) {
      od[val[i].second] = i;
      pos[i] = val[i].second;
    }
    for (int i = 1; i <= cnt; i++) num[i] = num[i - 1] + gval(pos[i]);
    dfs3(A);
  }
  int lca(int x, int y) {
    if (rdep[x] < rdep[y]) swap(x, y);
    int ddep = rdep[x] - rdep[y];
    for (int i = 0; i <= 16; i++)
      if (ddep & (1 << i)) x = fa[x][i];
    if (x == y) return x;
    for (int i = 16; i >= 0; i--)
      if (fa[x][i] != fa[y][i]) {
        x = fa[x][i];
        y = fa[y][i];
      }
    return fa[x][0];
  }
  int query(int x, int y) {
    y = 2 * y - 1;
    if (y >= cnt) return sum;
    int s = num[y], t = tp[x];
    if (od[lf[x]] <= y) return s;
    for (int i = 16; i >= 0; i--)
      if (od[lf[fa[t][i]]] > y) t = fa[t][i];
    s += dep[lf[x]] - dep[fa[t][0]];
    int u = fa[tp[pos[y]]][0], c = lca(x, pos[y]), ans = 0;
    if (rdep[c] <= rdep[u]) ans = s - (dep[pos[y]] - dep[u]);
    for (int i = 16; i >= 0; i--)
      if (minm[fa[x][i]] > y) x = fa[x][i];
    x = fa[x][0];
    return max(ans, s - (dep[lf[x]] - dep[x]));
  }
} At, Bt;
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &q);
  for (int i = 1; i < n; i++) {
    int x, y, s;
    scanf("%d%d%d", &x, &y, &s);
    sum += s;
    add(x, y, s);
    add(y, x, s);
  }
  dfs(1, -1);
  At.work(A);
  Bt.work(B);
  int lst = -1;
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (~lst) {
      x = (x + lst - 1) % n + 1;
      y = (y + lst - 1) % n + 1;
    }
    printf("%d\n", lst = max(At.query(x, y), Bt.query(x, y)));
  }
}
