#include <bits/stdc++.h>
using namespace std;
const int mn = 1e5 + 8, md = 18;
typedef int arr[mn];
int n, m, rt, tot, ans, f[mn][2], fa[mn][md];
arr U, D, ms, sum, idx;
pair<int, int> len[mn];
struct Edge {
  Edge *n;
  int v, c;
  Edge() {}
} * h[mn];
inline void addEdge(int u, int v, int c) {
  Edge *x = new Edge();
  x->v = v;
  x->n = h[u];
  h[u] = x;
  x->c = c;
}
void update(int u, int v) {
  if (v > f[u][0])
    f[u][1] = f[u][0], f[u][0] = v;
  else if (v > f[u][1])
    f[u][1] = v;
}
void down(int u, int fa) {
  f[u][0] = f[u][1] = 0;
  for (Edge *e = h[u]; e; e = e->n)
    if (e->v != fa) down(e->v, u), update(u, f[e->v][0] + e->c);
}
void up(int u, int fa, int tofa) {
  if (fa) update(u, tofa + f[fa][f[u][0] + tofa == f[fa][0]]);
  for (Edge *e = h[u]; e; e = e->n)
    if (e->v != fa) up(e->v, u, e->c);
}
void tour(int u) {
  for (int i = 0; fa[u][i]; i++) fa[u][i + 1] = fa[fa[u][i]][i];
  D[u] = ms[u] = 0;
  for (Edge *e = h[u]; e; e = e->n)
    if (e->v != fa[u][0]) {
      U[e->v] = U[u] + e->c;
      fa[e->v][0] = u;
      tour(e->v);
      if (e->c + D[e->v] > D[u]) ms[u] = e->v, D[u] = D[e->v] + e->c;
    }
}
void calc(int u, int dist) {
  if (ms[u]) {
    for (Edge *e = h[u]; e; e = e->n)
      if (e->v == ms[u]) calc(e->v, dist + e->c);
    for (Edge *e = h[u]; e; e = e->n)
      if (e->v != fa[u][0] && e->v != ms[u]) calc(e->v, e->c);
  } else
    len[++tot] = make_pair(-dist, u);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    addEdge(u, v, c);
    addEdge(v, u, c);
  }
  down(1, 0);
  up(1, 0, -1);
  for (int i = 1; i < n + 1; i++)
    if (!rt || f[i][0] < f[rt][0]) rt = i;
  tour(rt);
  calc(rt, 0);
  sort(len + 1, len + tot + 1);
  sum[0] = 0, idx[rt] = 1;
  for (int i = 1; i < tot + 1; i++) {
    sum[i] = sum[i - 1] - len[i].first;
    int u = len[i].second;
    while (!idx[u]) idx[u] = i, u = fa[u][0];
  }
  down(rt, 0);
  while (m--) {
    int u, c;
    scanf("%d%d", &u, &c);
    u = (u + ans - 1) % n + 1;
    c = (c + ans - 1) % n + 1;
    if (idx[u] <= 2 * c)
      ans = sum[min(2 * c, tot)];
    else {
      int par = u;
      for (int i = md - 1; i >= 0; i--)
        if (idx[fa[par][i]] > 2 * c) par = fa[par][i];
      par = fa[par][0];
      ans = sum[2 * c] + f[u][0] + U[u] - U[par] -
            min(-len[2 * c].first, f[par][0]);
    }
    printf("%d\n", ans);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
