#include <bits/stdc++.h>
using namespace std;
const int mn = 1e5 + 1;
typedef int arr[mn];
int n, m, rt, tot, ans, f[2][mn], fa[17][mn], p[mn], l;
arr U, D, ms, sum, idx;
pair<int, int> len[mn];
template <class T>
void rd(T& t) {
  char c;
  t = 0;
  while ((c = getchar()) < '0')
    ;
  do t = (t << 3) + (t << 1) + (c ^ 48);
  while ((c = getchar()) > '/');
}
struct edge {
  int next, v, c;
} h[mn * 2];
inline void add(int u, int v, int c) {
  h[++l] = (edge){p[u], v, c};
  p[u] = l;
}
void update(int u, int v) {
  if (v > f[0][u])
    f[1][u] = f[0][u], f[0][u] = v;
  else if (v > f[1][u])
    f[1][u] = v;
}
void down(int u, int fa) {
  f[0][u] = f[1][u] = 0;
  for (register int e = p[u]; e; e = h[e].next)
    if (h[e].v != fa) down(h[e].v, u), update(u, f[0][h[e].v] + h[e].c);
}
void up(int u, int fa, int tofa) {
  if (fa) update(u, tofa + f[f[0][u] + tofa == f[0][fa]][fa]);
  for (register int e = p[u]; e; e = h[e].next)
    if (h[e].v != fa) up(h[e].v, u, h[e].c);
}
void tour(int u) {
  for (int i = 0; fa[i][u]; i++) fa[i + 1][u] = fa[i][fa[i][u]];
  D[u] = ms[u] = 0;
  for (register int e = p[u]; e; e = h[e].next)
    if (h[e].v != fa[0][u]) {
      U[h[e].v] = U[u] + h[e].c;
      fa[0][h[e].v] = u;
      tour(h[e].v);
      if (h[e].c + D[h[e].v] > D[u]) ms[u] = h[e].v, D[u] = D[h[e].v] + h[e].c;
    }
}
void calc(int u, int dist) {
  if (ms[u]) {
    for (register int e = p[u]; e; e = h[e].next)
      if (h[e].v == ms[u]) calc(h[e].v, dist + h[e].c);
    for (register int e = p[u]; e; e = h[e].next)
      if (h[e].v != fa[0][u] && h[e].v != ms[u]) calc(h[e].v, h[e].c);
  } else
    len[++tot] = make_pair(-dist, u);
}
int main() {
  int u, v, c;
  rd(n);
  rd(m);
  for (register int i = 1; i < n; i++) {
    rd(u);
    rd(v);
    rd(c);
    add(u, v, c);
    add(v, u, c);
  }
  down(1, 0);
  up(1, 0, -1);
  for (register int i = 1; i < n + 1; i++)
    if (!rt || f[0][i] < f[0][rt]) rt = i;
  tour(rt);
  calc(rt, 0);
  sort(len + 1, len + tot + 1);
  idx[rt] = 1;
  for (register int i = 1; i < tot + 1; i++) {
    sum[i] = sum[i - 1] - len[i].first;
    u = len[i].second;
    while (!idx[u]) idx[u] = i, u = fa[0][u];
  }
  down(rt, 0);
  while (m--) {
    rd(u);
    rd(c);
    u = (ans + u - 1) % n + 1;
    c = (ans + c - 1) % n + 1;
    c <<= 1;
    if (idx[u] <= c)
      ans = sum[min(c, tot)];
    else {
      v = u;
      for (int i = 16; ~i; i--)
        if (idx[fa[i][v]] > c) v = fa[i][v];
      v = fa[0][v];
      ans = sum[c] + f[0][u] + U[u] - U[v] - min(-len[c].first, f[0][v]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
