#include <bits/stdc++.h>
using namespace std;
const int N = 100000, C = 21;
int n, cq;
struct side {
  int y, next, v;
} e[N * 2 + 9];
int lin[N + 9], cs;
void Ins(int x, int y, int v) {
  e[++cs].y = y;
  e[cs].v = v;
  e[cs].next = lin[x];
  lin[x] = cs;
}
void Ins2(int x, int y, int v) {
  Ins(x, y, v);
  Ins(y, x, v);
}
void into() {
  scanf("%d%d", &n, &cq);
  for (int i = 1; i < n; ++i) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    Ins2(x, y, v);
  }
}
queue<int> q;
int dis[N + 9], vis[N + 9];
int Bfs_dis(int st) {
  int res = st;
  for (int i = 1; i <= n; ++i) vis[i] = 0;
  dis[st] = 0;
  vis[st] = 1;
  q.push(st);
  for (; !q.empty();) {
    int t = q.front();
    q.pop();
    if (dis[t] > dis[res]) res = t;
    for (int i = lin[t]; i; i = e[i].next)
      if (!vis[e[i].y]) {
        dis[e[i].y] = dis[t] + e[i].v;
        vis[e[i].y] = 1;
        q.push(e[i].y);
      }
  }
  return res;
}
struct tree {
  int rot;
  int gr[N + 9][C], son[N + 9], dep[N + 9], len[N + 9];
  int dis[N + 9];
  void Dfs_ord0(int k, int fat) {
    gr[k][0] = fat;
    for (int i = 1; i < C; ++i) gr[k][i] = gr[gr[k][i - 1]][i - 1];
    dep[k] = dep[fat] + 1;
    for (int i = lin[k]; i; i = e[i].next)
      if (e[i].y ^ fat) {
        dis[e[i].y] = dis[k] + e[i].v;
        Dfs_ord0(e[i].y, k);
        if (len[e[i].y] + e[i].v > len[k])
          len[k] = len[e[i].y] + e[i].v, son[k] = e[i].y;
      }
  }
  int d[N + 9], val[N + 9], ca;
  void Dfs_ord1(int k, int t, int v) {
    if (k == t) d[++ca] = k, val[k] = v + len[k];
    bel[k] = ca;
    if (son[k]) Dfs_ord1(son[k], t, 0);
    for (int i = lin[k]; i; i = e[i].next)
      if (e[i].y ^ gr[k][0] && e[i].y ^ son[k])
        Dfs_ord1(e[i].y, e[i].y, e[i].v);
  }
  int Query_anc(int k, int lim) {
    for (int i = C - 1; i >= 0; --i)
      if (bel[gr[k][i]] > lim) k = gr[k][i];
    return gr[k][0];
  }
  int bel[N + 9], a[N + 9], sum[N + 9];
  void Get_tr() {
    Dfs_ord0(rot, 0);
    Dfs_ord1(rot, rot, 0);
    sort(d + 1, d + ca + 1, [&](const int &x, const int &y) {
      return val[x] > val[y] || val[x] == val[y] && dep[x] < dep[y];
    });
    for (int i = 1; i <= ca; ++i) {
      for (int k = d[i]; k; k = son[k]) bel[k] = i;
      sum[i] = sum[i - 1] + (a[i] = val[d[i]]);
    }
  }
  int Query_ans(int k, int c) {
    if (c >= ca) return sum[ca];
    if (bel[k] <= c) return sum[c];
    int now = sum[c];
    int x = Query_anc(k, c - 1), y = Query_anc(k, c);
    return now + len[k] + dis[k] - min(a[c] + dis[x], len[y] + dis[y]);
  }
} tr[2];
void Get_tr() {
  tr[0].rot = Bfs_dis(1);
  tr[1].rot = Bfs_dis(tr[0].rot);
  tr[0].Get_tr();
  tr[1].Get_tr();
}
void work() { Get_tr(); }
void getans() {
  int ans = 0;
  for (; cq--;) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + ans - 1) % n + 1;
    y = (y + ans - 1) % n + 1;
    y = 2 * y - 1;
    printf("%d\n", ans = max(tr[0].Query_ans(x, y), tr[1].Query_ans(x, y)));
  }
}
int main() {
  into();
  work();
  getans();
  return 0;
}
