#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, q, rt, dis[N], head[N], cnt;
struct edge {
  int next, to, w;
} a[N << 1];
struct seg {
  int val, x;
};
seg max(seg a, seg b) { return a.val > b.val ? a : b; }
void link(int x, int y, int w) {
  a[++cnt] = (edge){head[x], y, w};
  head[x] = cnt;
}
struct Tree {
  int rt, dis[N];
  int siz[N], dfn[N], tot, leaf, tag[N << 2], del[N], id[N];
  int mxlf[N], fa[20][N], Smn[20][N], Smx[20][N], tof[20][N];
  seg t[N << 2], Ans[N];
  void dfs(int x, int fr) {
    dfn[x] = ++tot;
    id[tot] = x;
    siz[x] = 1;
    mxlf[x] = x;
    for (int i = head[x]; i; i = a[i].next) {
      int R = a[i].to;
      if (R == fr) continue;
      fa[0][R] = x;
      dis[R] = dis[x] + a[i].w;
      tof[0][R] = a[i].w;
      dfs(R, x);
      siz[x] += siz[R];
      if (dis[mxlf[x]] < dis[mxlf[R]]) mxlf[x] = mxlf[R];
    }
    leaf += (siz[x] == 1);
  }
  void build(int x, int l, int r) {
    if (l == r) {
      if (siz[id[l]] == 1)
        t[x] = (seg){dis[id[l]], id[l]};
      else
        t[x] = (seg){(int)-1e9, 0};
      return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    t[x] = max(t[x << 1], t[x << 1 | 1]);
  }
  void put(int x, int k) {
    t[x].val += k;
    tag[x] += k;
  }
  void pushdown(int x) {
    int &v = tag[x];
    if (v) put(x << 1, v), put(x << 1 | 1, v), v = 0;
  }
  void Add(int x, int l, int r, int gl, int gr, int k) {
    if (l >= gl && r <= gr) {
      put(x, k);
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(x);
    if (gl <= mid) Add(x << 1, l, mid, gl, gr, k);
    if (gr > mid) Add(x << 1 | 1, mid + 1, r, gl, gr, k);
    t[x] = max(t[x << 1], t[x << 1 | 1]);
  }
  void init(int _rt) {
    dfs(rt = _rt, 0);
    build(1, 1, n);
    for (int i = 1, w; i <= leaf; i++) {
      Ans[i] = t[1];
      w = t[1].x;
      for (int x = w; !del[x] && x; del[x] = i, x = fa[0][x])
        Add(1, 1, n, dfn[x], dfn[x] + siz[x] - 1, -(dis[x] - dis[fa[0][x]]));
    }
    for (int i = 1; i <= leaf; i++) Ans[i].val += Ans[i - 1].val;
    for (int i = 1; i <= n; i++) Smn[0][i] = Smx[0][i] = del[i];
    for (int p = 1; p <= 18; p++)
      for (int i = 1; i <= n; i++) {
        fa[p][i] = fa[p - 1][fa[p - 1][i]];
        tof[p][i] = tof[p - 1][i] + tof[p - 1][fa[p - 1][i]];
        Smn[p][i] = min(Smn[p - 1][i], Smn[p - 1][fa[p - 1][i]]);
        Smx[p][i] = max(Smx[p - 1][i], Smx[p - 1][fa[p - 1][i]]);
      }
  }
  int solve(int x, int y) {
    if (y >= leaf) return Ans[leaf].val;
    if (del[x] <= y) return Ans[y].val;
    int u = x, res = 0, ans = 0;
    for (int p = 18; p >= 0; p--)
      if (Smn[p][u] > y) res += tof[p][u], u = fa[p][u];
    ans = Ans[y - 1].val + res + dis[mxlf[x]] - dis[x];
    res = 0;
    for (int p = 18; p >= 0; p--)
      if (fa[p][u]) res = max(res, Smx[p][u]), u = fa[p][u];
    int nw = Ans[y].val - dis[Ans[res].x] + dis[mxlf[x]];
    return max(ans, nw);
  }
} T[2];
void dfs(int x, int fr) {
  for (int i = head[x]; i; i = a[i].next)
    if (a[i].to != fr) dis[a[i].to] = dis[x] + a[i].w, dfs(a[i].to, x);
}
int Getnxt(int x) {
  dis[x] = 0;
  dfs(x, 0);
  int res = 1;
  for (int i = 2; i <= n; i++)
    if (dis[i] > dis[res]) res = i;
  return res;
}
int main() {
  cin >> n >> q;
  for (int i = 2, x, y, w; i <= n; i++) {
    scanf("%d%d%d", &x, &y, &w);
    link(x, y, w);
    link(y, x, w);
  }
  rt = Getnxt(1);
  T[0].init(rt);
  rt = Getnxt(rt);
  T[1].init(rt);
  for (int i = 1, ans = 0, x, y; i <= q; i++, printf("%d\n", ans)) {
    scanf("%d%d", &x, &y);
    x = (x + ans - 1) % n + 1;
    y = (y + ans - 1) % n + 1;
    y = y * 2 - 1;
    ans = max(T[0].solve(x, y), T[1].solve(x, y));
  }
  return 0;
}
