#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 998244353;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int to[N << 1], nt[N << 1], w[N << 1], hd[N], tot = 1;
void adde(int x, int y, int z) {
  ++tot, to[tot] = y, nt[tot] = hd[x], w[tot] = z, hd[x] = tot;
  ++tot, to[tot] = x, nt[tot] = hd[y], w[tot] = z, hd[y] = tot;
}
int s1[N * 70], s2[N * 70], ch[N * 70][2], rt[N], tt, vl = 1, vr = 1e8;
void inst(int o1, int o2, int x, int dx) {
  s1[o1] = s1[o2] + dx, s2[o1] = s2[o2] + x * dx;
  int l = vl, r = vr;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (x <= mid) {
      ch[o1][0] = ++tt, ch[o1][1] = ch[o2][1];
      o1 = ch[o1][0], o2 = ch[o2][0];
      r = mid;
    } else {
      ch[o1][0] = ch[o2][0], ch[o1][1] = ++tt;
      o1 = ch[o1][1], o2 = ch[o2][1];
      l = mid + 1;
    }
    s1[o1] = s1[o2] + dx, s2[o1] = s2[o2] + x * dx;
  }
}
int a1, a2;
int q1(int o, int l, int r, int k) {
  if (l == r) return l;
  int mid = (l + r) >> 1;
  if (s1[ch[o][1]] < k) {
    a1 += s1[ch[o][1]], a2 += s2[ch[o][1]];
    return q1(ch[o][0], l, mid, k - s1[ch[o][1]]);
  } else
    return q1(ch[o][1], mid + 1, r, k);
}
int n, q, dt[N], r1, r2, fa[N], fw[N], de[N], dp[N], hs[N], top[N], zl[N], fy;
void dfs0(int x) {
  dt[x] = max(dt[x], de[x]);
  if (de[r1] < de[x]) r1 = x;
  for (int i = hd[x]; i; i = nt[i]) {
    int y = to[i];
    if (y == fa[x]) continue;
    fa[y] = x, de[y] = de[x] + w[i], dfs0(y);
  }
}
void dfs1(int x) {
  dp[x] = de[x];
  for (int i = hd[x]; i; i = nt[i]) {
    int y = to[i];
    if (y == fa[x]) continue;
    fa[y] = x, fw[y] = w[i], de[y] = de[x] + w[i], dfs1(y);
    if (dp[y] > dp[x]) dp[x] = dp[y], hs[x] = y;
  }
}
void dfs2(int x) {
  if (hs[x]) top[hs[x]] = top[x], dfs2(hs[x]);
  for (int i = hd[x]; i; i = nt[i]) {
    int y = to[i];
    if (y == fa[x] || y == hs[x]) continue;
    top[y] = y, dfs2(y);
  }
}
void dfs3(int x) {
  for (int i = hd[x]; i; i = nt[i]) {
    int y = to[i];
    if (y == fa[x]) continue;
    rt[y] = rt[x];
    if (y != hs[x]) {
      int las = rt[y];
      inst(rt[y] = ++tt, las, x == r1 ? zl[fy] : dp[x] - de[x], 1);
      las = rt[y];
      inst(rt[y] = ++tt, las, zl[y], -1);
    }
    dfs3(y);
  }
}
int main() {
  n = rd(), q = rd();
  for (int i = 1; i < n; ++i) {
    int x = rd(), y = rd(), z = rd();
    adde(x, y, z);
  }
  dfs0(1);
  r2 = r1, r1 = 0, fa[r2] = de[r2] = 0, dfs0(r2);
  r2 = r1, r1 = 0, fa[r2] = de[r2] = 0, dfs0(r2);
  int nl = de[r1];
  while (fa[r1] != r2 && de[r1] > nl - de[r1]) r1 = fa[r1];
  fa[r1] = de[r1] = 0;
  dfs1(r1), top[r1] = r1, dfs2(r1);
  for (int i = 1; i <= n; ++i)
    if (top[i] == i) {
      int las = rt[0];
      inst(rt[0] = ++tt, las, zl[i] = dp[i] - de[i] + fw[i], 1);
    }
  int nm = s1[rt[0]], zans = s2[rt[0]], las;
  inst(rt[r1] = ++tt, rt[0], zl[r1], -1), dt[r1] = nl;
  las = rt[r1], inst(rt[r1] = ++tt, las, nl - zl[r1], -1);
  for (int i = 1; i <= n; ++i)
    if (i != r1) dt[i] += dp[i] - de[i];
  for (int i = hd[r1]; i; i = nt[i]) {
    int y = to[i];
    if (y == hs[r1]) continue;
    fy = dp[fy] > dp[y] ? fy : y;
  }
  dfs3(r1);
  int ans = 0;
  while (q--) {
    int x = (rd() + ans - 1) % n + 1, y = ((rd() + ans - 1) % n + 1) * 2;
    if (y >= nm)
      ans = zans;
    else {
      y -= 2, ans = dt[x];
      a1 = a2 = 0;
      int nv = q1(rt[x], vl, vr, y);
      ans += a2 + (y - a1) * nv;
    }
    printf("%d\n", ans);
  }
  return 0;
}
