#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int n, Q;
int h[M], nx[M << 1], to[M << 1], v[M << 1], tot;
void add(int a, int b, int c) {
  to[++tot] = b;
  v[tot] = c;
  nx[tot] = h[a];
  h[a] = tot;
}
struct Tree {
  int mx[M], dis[M], sum[M];
  int son[M], fa[M][17], when[M], cnt;
  struct node {
    int num;
    int hd;
    bool operator<(const node &_) const { return num > _.num; }
  } a[M];
  void dfs(int x) {
    for (int i = 1; i < 17; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
    for (int i = h[x]; i; i = nx[i]) {
      int y = to[i];
      if (y == fa[x][0]) continue;
      fa[y][0] = x, dis[y] = dis[x] + v[i];
      dfs(y);
      if (mx[x] < mx[y] + v[i]) mx[x] = mx[y] + v[i], son[x] = y;
    }
  }
  void init(int rt) {
    dfs(rt);
    a[++cnt] = (node){mx[rt], rt};
    for (int z = 1; z <= n; z++) {
      for (int i = h[z]; i; i = nx[i]) {
        int y = to[i];
        if (y == fa[z][0] || y == son[z]) continue;
        a[++cnt] = (node){mx[y] + v[i], y};
      }
    }
    sort(a + 1, a + 1 + cnt);
    for (int i = 1; i <= cnt; i++) {
      for (int j = a[i].hd; j; j = son[j]) when[j] = i;
      sum[i] = sum[i - 1] + a[i].num;
    }
  }
  int query(int x, int y) {
    y = y * 2 - 1;
    if (when[x] <= y) return sum[min(y, cnt)];
    int z = x;
    for (int i = 16; i >= 0; i--)
      if (fa[x][i] && when[fa[x][i]] > y) x = fa[x][i];
    x = fa[x][0];
    return sum[y] - min(a[y].num, mx[x]) + (dis[z] - dis[x] + mx[z]);
  }
} tr[2];
int mxdis;
int id;
void Find(int x, int f, int d) {
  if (mxdis < d) mxdis = d, id = x;
  for (int i = h[x]; i; i = nx[i]) {
    int y = to[i];
    if (y == f) continue;
    Find(y, x, d + v[i]);
  }
}
void init() {
  mxdis = -1;
  Find(1, 0, 0);
  tr[0].init(id);
  mxdis = -1;
  Find(id, 0, 0);
  tr[1].init(id);
}
int main() {
  scanf("%d%d", &n, &Q);
  for (int x, y, z, i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
  }
  init();
  int ans = 0;
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + ans - 1) % n + 1;
    y = (y + ans - 1) % n + 1;
    printf("%d\n", ans = max(tr[0].query(x, y), tr[1].query(x, y)));
  }
  return 0;
}
