#include <bits/stdc++.h>
using namespace std;
int addnum, vel[200010], ne[200010], key[200010], head[100010];
int suma[100010], sumb[100010], mxa[100010], mxb[100010];
int ida[100010], idb[100010], da[100010], db[100010], a[100010], b[100010],
    sa[100010], sb[100010], pa[100010], pb[100010];
int sona[100010], sonb[100010], topsa[100010], topsb[100010], fata[100010][21],
    fatb[100010][21];
int n, q, rt, ed;
inline int read() {
  int ans = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  return ans;
}
void add(int u, int v, int k) {
  addnum++, vel[addnum] = v, key[addnum] = k, ne[addnum] = head[u],
            head[u] = addnum;
}
void dfs(int u, int fa) {
  rt = a[u] > a[rt] ? u : rt;
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    a[v] = a[u] + key[e];
    dfs(v, u);
  }
}
void dfs1(int u, int fa) {
  ed = a[u] > a[ed] ? u : ed;
  mxa[u] = a[u];
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    a[v] = a[u] + key[e];
    dfs1(v, u);
    sona[u] = mxa[v] > mxa[sona[u]] ? v : sona[u];
    mxa[u] = max(mxa[u], mxa[v]);
  }
}
void dfst1(int u, int fa, int top) {
  sa[top] = max(sa[top], a[u]);
  topsa[u] = top;
  if (sona[u]) fata[sona[u]][0] = u, dfst1(sona[u], u, top);
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa || v == sona[u]) continue;
    fata[v][0] = u;
    dfst1(v, u, v);
    sa[v] -= a[u];
  }
}
void dfs2(int u, int fa) {
  mxb[u] = b[u];
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    b[v] = b[u] + key[e];
    dfs2(v, u);
    sonb[u] = mxb[v] > mxb[sonb[u]] ? v : sonb[u];
    mxb[u] = max(mxb[u], mxb[v]);
  }
}
void dfst2(int u, int fa, int top) {
  sb[top] = max(sb[top], b[u]);
  topsb[u] = top;
  if (sonb[u]) fatb[sonb[u]][0] = u, dfst2(sonb[u], u, top);
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa || v == sonb[u]) continue;
    fatb[v][0] = u;
    dfst2(v, u, v);
    sb[v] -= b[u];
  }
}
inline int cmpa(int x, int y) { return sa[x] > sa[y]; }
inline int cmpb(int x, int y) { return sb[x] > sb[y]; }
int main() {
  n = read();
  q = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read(), z = read();
    add(x, y, z), add(y, x, z);
  }
  rt = 1;
  dfs(1, -1);
  ed = rt;
  a[rt] = 0;
  dfs1(rt, -1);
  dfst1(rt, -1, rt);
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++) fata[j][i] = fata[fata[j][i - 1]][i - 1];
  for (int i = 1; i <= n; i++) ida[i] = i;
  sort(ida + 1, ida + n + 1, cmpa);
  for (int i = 1; i <= n; i++) da[ida[i]] = i;
  for (int i = 1; i <= n; i++) pa[i] = da[topsa[i]];
  for (int i = 1; i <= n; i++) suma[i] = suma[i - 1] + sa[ida[i]];
  dfs2(ed, -1);
  dfst2(ed, -1, ed);
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++) fatb[j][i] = fatb[fatb[j][i - 1]][i - 1];
  for (int i = 1; i <= n; i++) idb[i] = i;
  sort(idb + 1, idb + n + 1, cmpb);
  for (int i = 1; i <= n; i++) db[idb[i]] = i;
  for (int i = 1; i <= n; i++) pb[i] = db[topsb[i]];
  for (int i = 1; i <= n; i++) sumb[i] = sumb[i - 1] + sb[idb[i]];
  int last = 0;
  while (q--) {
    int x = read(), y = read();
    x = (x + last - 1) % n + 1, y = (y + last - 1) % n + 1;
    int dx = x, dy = y;
    int ansa = 2 * y - 1 > n ? suma[n] : suma[2 * y - 1];
    if (pa[x] > 2 * y - 1) {
      int num = sa[topsa[x]] + a[fata[topsa[x]][0]];
      for (int i = 19; i >= 0; i--)
        if (pa[fata[x][i]] > 2 * y - 1) x = fata[x][i];
      x = fata[x][0];
      num -= a[x];
      ansa =
          ansa + num -
          min(sa[ida[2 * y - 1]], sa[topsa[x]] + a[fata[topsa[x]][0]] - a[x]);
    }
    x = dx, y = dy;
    int ansb = 2 * y - 1 > n ? sumb[n] : sumb[2 * y - 1];
    if (pb[x] > 2 * y - 1) {
      int num = sb[topsb[x]] + b[fatb[topsb[x]][0]];
      for (int i = 19; i >= 0; i--)
        if (pb[fatb[x][i]] > 2 * y - 1) x = fatb[x][i];
      x = fatb[x][0];
      num -= b[x];
      ansb =
          ansb + num -
          min(sb[idb[2 * y - 1]], sb[topsb[x]] + b[fatb[topsb[x]][0]] - b[x]);
    }
    last = max(ansa, ansb);
    printf("%d\n", last);
  }
}
