#include <bits/stdc++.h>
using namespace std;
const int maxn(1e5 + 5);
struct Edge {
  int to, next, w;
} edge[maxn << 1];
int n, q, first[maxn], cnt, mxd, mxv;
inline void Add(int u, int v, int w) {
  edge[cnt] = (Edge){v, first[u], w}, first[u] = cnt++;
  edge[cnt] = (Edge){u, first[v], w}, first[v] = cnt++;
}
struct Struction {
  int rt, fa[18][maxn], dfn[maxn], ed[maxn], ans[maxn], mxdis[maxn];
  int deep[maxn], idx, id[maxn], vis[maxn], tag[maxn << 2];
  pair<int, int> mx[maxn << 2];
  void Dfs(int u, int ff) {
    int e, v;
    dfn[u] = ++idx, id[idx] = u;
    for (e = first[u]; ~e; e = edge[e].next)
      if ((v = edge[e].to) ^ ff) {
        mxdis[v] = deep[v] = deep[u] + edge[e].w;
        fa[0][v] = u, Dfs(v, u);
        mxdis[u] = max(mxdis[u], mxdis[v]);
      }
    ed[u] = idx;
  }
  void Build(int x, int l, int r) {
    if (l == r)
      mx[x] = make_pair(deep[id[l]], id[l]);
    else {
      int mid = (l + r) >> 1;
      Build(x << 1, l, mid), Build(x << 1 | 1, mid + 1, r);
      mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
    }
  }
  void Modify(int x, int l, int r, int ql, int qr, int v) {
    if (ql <= l && qr >= r)
      mx[x].first += v, tag[x] += v;
    else {
      int mid = (l + r) >> 1;
      if (ql <= mid) Modify(x << 1, l, mid, ql, qr, v);
      if (qr > mid) Modify(x << 1 | 1, mid + 1, r, ql, qr, v);
      mx[x] = max(mx[x << 1], mx[x << 1 | 1]), mx[x].first += tag[x];
    }
  }
  inline void Init(int _rt) {
    int i, j;
    rt = _rt, Dfs(rt, 0), Build(1, 1, n);
    for (j = 1; j < 18; ++j)
      for (i = 1; i <= n; ++i) fa[j][i] = fa[j - 1][fa[j - 1][i]];
    for (i = 2; i <= n; ++i) {
      ans[i] = ans[i - 1] + mx[1].first;
      for (j = mx[1].second; j && !vis[j]; j = fa[0][j])
        vis[j] = i, Modify(1, 1, n, dfn[j], ed[j], deep[fa[0][j]] - deep[j]);
    }
  }
  inline int Solve(int x, int y) {
    y = min(y, n);
    if (vis[x] <= y) return ans[y];
    int cur = x, i;
    for (i = 17; ~i; --i)
      if (vis[fa[i][x]] > y) x = fa[i][x];
    x = fa[0][x];
    return ans[y] + mxdis[cur] - deep[x] -
           min(min(ans[y] - ans[y - 1], mxdis[x] - deep[x]), deep[x]);
  }
} t1, t2;
void Dfs(int u, int ff, int d) {
  int e, v;
  if (d > mxv) mxv = d, mxd = u;
  for (e = first[u]; ~e; e = edge[e].next)
    if ((v = edge[e].to) != ff) Dfs(v, u, d + edge[e].w);
}
int main() {
  int i, u, v, w;
  memset(first, -1, sizeof(first));
  scanf("%d%d", &n, &q);
  for (i = 1; i < n; ++i) scanf("%d%d%d", &u, &v, &w), Add(u, v, w);
  mxv = -1, Dfs(1, 0, 0), t1.Init(mxd), mxv = -1, Dfs(mxd, 0, 0), t2.Init(mxd);
  for (w = 0, i = 1; i <= q; ++i) {
    scanf("%d%d", &u, &v);
    u = (u + w - 1) % n + 1, v = (v + w - 1) % n + 1;
    printf("%d\n", w = min(t1.Solve(u, v << 1), t2.Solve(u, v << 1)));
  }
  return 0;
}
