#include <bits/stdc++.h>
using namespace std;
inline void rd(int &res) {
  res = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do res = (res << 1) + (res << 3) + (c ^ 48);
  while (c = getchar(), c >= 48);
}
inline void print(int x) {
  if (!x) return;
  print(x / 10);
  putchar((x % 10) ^ 48);
}
inline void sc(int x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  print(x);
  if (!x) putchar('0');
  putchar('\n');
}
inline void Max(int &x, int y) {
  if (x < y) x = y;
}
inline void Min(int &x, int y) {
  if (x > y) x = y;
}
const int M = 1e5 + 5;
int cnt[M], pos[M], mark[M], ed[M], id[M], g[M], head[M], val[M], A[M], fa[M],
    sum[M];
int dis[M], n, m, ID1, ID2, D, ec = 0, tot = 0, po = 0;
struct Edge {
  int to, v, nex;
} e[M << 1];
struct node {
  int val, p;
} Q[M];
bool cmp(node a, node b) { return a.val > b.val; }
void add_edge(int a, int b, int c) {
  e[ec] = (Edge){b, c, head[a]};
  head[a] = ec++;
  e[ec] = (Edge){a, c, head[b]};
  head[b] = ec++;
}
void dfs(int x, int f, int d, int v) {
  if (d >= D) {
    D = d;
    ID1 = x;
  }
  ed[x] = v;
  fa[x] = f;
  for (int i = head[x]; ~i; i = e[i].nex) {
    int y = e[i].to;
    if (y == f) continue;
    dfs(y, x, d + e[i].v, e[i].v);
  }
}
void rdfs(int h, int x, int f, int v, int d) {
  id[x] = h;
  g[x] = x;
  fa[x] = f;
  ed[x] = v;
  dis[x] = d;
  for (int i = head[x]; ~i; i = e[i].nex) {
    int y = e[i].to;
    if (y == f || mark[y]) continue;
    rdfs(h, y, x, e[i].v, d + e[i].v);
    if (dis[g[y]] > dis[g[x]]) g[x] = g[y];
  }
}
void rdfs2(int x, int f, int an, int d) {
  for (int i = head[x]; ~i; i = e[i].nex) {
    int y = e[i].to;
    if (f == y || mark[y]) continue;
    if (g[x] == g[y])
      rdfs2(y, x, an, d + e[i].v);
    else
      rdfs2(y, x, x, e[i].v);
  }
  if (g[x] == x && !mark[x]) Q[++po] = (node){d, x};
}
void solve() {
  dfs(1, -1, 0, 0);
  ID2 = ID1;
  dfs(ID2, -1, 0, 0);
  int i, j, k, x, y, a, b, c = 0, ans, res, w;
  x = ID1;
  while (x != -1) {
    id[x] = ++tot;
    A[tot] = x;
    mark[x] = 1;
    val[x] = c;
    c += ed[x];
    x = fa[x];
  }
  for (i = 1; i <= tot; i++) {
    rdfs(i, A[i], A[i], 0, 0);
    rdfs2(A[i], A[i], A[i], 0);
  }
  sort(Q + 1, Q + 1 + po, cmp);
  for (i = 1; i <= po; i++) {
    pos[Q[i].p] = i;
    sum[i] = sum[i - 1] + Q[i].val;
  }
  sum[po + 1] = sum[po];
  for (j = 1; j <= m; j++) {
    rd(x);
    rd(y);
    if (j > 1) {
      x = (x + ans - 1) % n + 1;
      y = (y + ans - 1) % n + 1;
    }
    y = min((y - 1) * 2, po + 1);
    if (mark[x])
      ans = D + sum[y];
    else {
      ans = 0, w = id[x], res = min(val[A[id[x]]], D - val[A[id[x]]]);
      int k = y + 1, mi = Q[y].val, a = g[x], b = 0, tmp = 0;
      ans = D - res + dis[g[x]] + sum[y];
      if (!y) {
        sc(ans);
        continue;
      }
      if (dis[g[x]] == Q[pos[g[x]]].val) {
        if (pos[g[x]] <= y) {
          ans += Q[y + 1].val - dis[g[x]];
          mi = Q[y + 1].val;
        }
        if (res > mi) ans += res - mi;
        sc(ans);
        continue;
      }
      cnt[k] = 0;
      while (!mark[a]) {
        if (pos[g[a]] <= y) {
          ans -= dis[g[a]];
          b = max(dis[g[a]] - dis[a], Q[k].val - cnt[k]);
          ans += b;
          Min(mi, b);
          break;
        }
        cnt[pos[g[a]]] += ed[a];
        a = fa[a];
      }
      if (res > mi) ans += res - mi;
    }
    sc(ans);
  }
}
int main() {
  memset(head, -1, sizeof(head));
  rd(n);
  rd(m);
  int i, j, a, b, c;
  for (i = 1; i < n; i++) {
    rd(a);
    rd(b);
    rd(c);
    add_edge(a, b, c);
  }
  solve();
  return 0;
}
