#include <bits/stdc++.h>
using namespace std;
int n, q, h[100005], cnt, d1, d2, dis[100005], tmp[100005], qz1[100005],
    qz2[100005];
int md1[100005], mh1[100005], b1[100005], son1[100005], fa1[100005][20],
    p1[100005][20], dis1[100005];
int md2[100005], mh2[100005], b2[100005], son2[100005], fa2[100005][20],
    p2[100005][20], dis2[100005];
struct node {
  int to, next, val;
} e[100005 << 1];
inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (ch < 48 || ch > 57) f |= (ch == '-'), ch = getchar();
  while (ch > 47 && ch < 58)
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}
void Addedge(int x, int y, int z) {
  e[++cnt] = (node){y, h[x], z}, h[x] = cnt;
  e[++cnt] = (node){x, h[y], z}, h[y] = cnt;
}
void Dfs(int x, int fa) {
  for (int i = h[x], y; i; i = e[i].next)
    if (y = e[i].to, y != fa) dis[y] = dis[x] + e[i].val, Dfs(y, x);
}
void Getzj() {
  Dfs(1, dis[1] = 0);
  for (int i = d1 = 1; i <= n; ++i)
    if (dis[i] > dis[d1]) d1 = i;
  Dfs(d1, dis[d1] = 0);
  for (int i = d2 = 1; i <= n; ++i)
    if (dis[i] > dis[d2]) d2 = i;
}
void Work1(int x, int *dis, int *md, int *son, int (*fa)[20]) {
  for (int i = h[x], y; i; i = e[i].next)
    if (y = e[i].to, y != fa[x][0]) {
      dis[y] = dis[fa[y][0] = x] + e[i].val, Work1(y, dis, md, son, fa);
      md[x] < md[y] + e[i].val && (md[x] = md[y] + e[i].val, son[x] = y);
    }
}
void Work2(int x, int top, int *mh, int *son, int *b, int (*fa)[20]) {
  if (b[x] = top, top == x && (tmp[++tmp[0]] = x), son[x])
    Work2(son[x], top, mh, son, b, fa);
  for (int i = h[x], y; i; i = e[i].next)
    if (y = e[i].to, y != fa[x][0] && y != son[x])
      mh[y] += e[i].val, Work2(y, y, mh, son, b, fa);
}
bool cmp1(int x, int y) { return md1[x] + mh1[x] > md1[y] + mh1[y]; }
bool cmp2(int x, int y) { return md2[x] + mh2[x] > md2[y] + mh2[y]; }
int main() {
  n = read(), q = read();
  for (int i = 1, x, y, z; i < n; ++i)
    x = read(), y = read(), z = read(), Addedge(x, y, z);
  Getzj();
  tmp[0] = 0, Work1(d1, dis1, md1, son1, fa1),
  Work2(d1, d1, mh1, son1, b1, fa1), sort(tmp + 1, tmp + tmp[0] + 1, cmp1);
  for (int i = 1; i <= tmp[0]; ++i) p1[tmp[i]][0] = i;
  for (int i = 1; i <= n; ++i)
    p1[i][0] = p1[b1[i]][0], qz1[i] = qz1[i - 1] + md1[tmp[i]] + mh1[tmp[i]];
  for (int j = 1; j <= 18; ++j)
    for (int i = 1; i <= n; ++i)
      fa1[i][j] = fa1[fa1[i][j - 1]][j - 1],
      p1[i][j] = min(p1[i][j - 1], p1[fa1[i][j - 1]][j - 1]);
  tmp[0] = 0, Work1(d2, dis2, md2, son2, fa2),
  Work2(d2, d2, mh2, son2, b2, fa2), sort(tmp + 1, tmp + tmp[0] + 1, cmp2);
  for (int i = 1; i <= tmp[0]; ++i) p2[tmp[i]][0] = i;
  for (int i = 1; i <= n; ++i)
    p2[i][0] = p2[b2[i]][0], qz2[i] = qz2[i - 1] + md2[tmp[i]] + mh2[tmp[i]];
  for (int j = 1; j <= 18; ++j)
    for (int i = 1; i <= n; ++i)
      fa2[i][j] = fa2[fa2[i][j - 1]][j - 1],
      p2[i][j] = min(p2[i][j - 1], p2[fa2[i][j - 1]][j - 1]);
  for (int i = 1, x, y, z, las = 0; i <= q; ++i) {
    z = x = (read() + las - 1) % n + 1,
    y = min(n, ((read() + las - 1) % n + 1) * 2 - 1), las = 0;
    if (p1[x][0] <= y)
      las = max(las, qz1[y]);
    else {
      for (int j = 18; ~j; --j)
        if (p1[z][j] > y) z = fa1[z][j];
      las = max(las, qz1[y] + md1[x] + dis1[x] - dis1[z] -
                         min(md1[z], qz1[y] - qz1[y - 1]));
    }
    if (p2[x][0] <= y)
      las = max(las, qz2[y]);
    else {
      for (int j = 18; ~j; --j)
        if (p2[z][j] > y) z = fa2[z][j];
      las = max(las, qz2[y] + md2[x] + dis2[x] - dis2[z] -
                         min(md2[z], qz2[y] - qz2[y - 1]));
    }
    cout << las << "\n";
  }
  return 0;
}
