#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline", "no-stack-protector", "unroll-loops")
using namespace std;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class I>
inline void gi(I &x) {
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = (x << 1) + (x << 3) + (c & 15);
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::gi;
using io ::print;
using io ::putc;
const int N = 100005;
int a[N];
struct Segment {
  int val[N << 2], tag[N << 2], pos[N << 2];
  void pushdown(int root) {
    if (tag[root]) {
      tag[root << 1] += tag[root];
      tag[(root << 1) | 1] += tag[root];
      val[root << 1] += tag[root];
      val[(root << 1) | 1] += tag[root];
      tag[root] = 0;
    }
  }
  void pushup(int root) {
    val[root] = max(val[root << 1], val[(root << 1) | 1]);
    pos[root] =
        (val[root] == val[root << 1] ? pos[root << 1] : pos[(root << 1) | 1]);
  }
  void build(int root, int l, int r) {
    if (l == r) {
      val[root] = a[l], pos[root] = l;
      return;
    }
    build(root << 1, l, ((l + r) >> 1));
    build((root << 1) | 1, ((l + r) >> 1) + 1, r);
    pushup(root);
  }
  void update(int root, int l, int r, int L, int R, int v) {
    if (r < L || l > R) return;
    if (L <= l && r <= R) {
      tag[root] += v, val[root] += v;
      return;
    }
    pushdown(root);
    update(root << 1, l, ((l + r) >> 1), L, R, v);
    update((root << 1) | 1, ((l + r) >> 1) + 1, r, L, R, v);
    pushup(root);
  }
} Seg;
int Head[N], Next[N << 1], Adj[N << 1], Weight[N << 1], tot = 0;
void addedge(int u, int v, int w) {
  Next[++tot] = Head[u], Head[u] = tot, Adj[tot] = v, Weight[tot] = w;
  Next[++tot] = Head[v], Head[v] = tot, Adj[tot] = u, Weight[tot] = w;
}
int now, len;
void get(int x, int f, int d) {
  if (d >= len) len = d, now = x;
  for (int e = Head[x]; e; e = Next[e])
    if (Adj[e] != f) get(Adj[e], x, d + Weight[e]);
}
int n, m;
struct Tree {
  Segment Seg;
  int fa[N], size[N];
  int dfn[N], to[N], Time, up[N], dep[N], mx[N];
  void dfs1(int x) {
    dfn[x] = ++Time, to[Time] = x;
    mx[x] = dep[x], size[x] = 1;
    for (int e = Head[x]; e; e = Next[e])
      if (Adj[e] != fa[x]) {
        fa[Adj[e]] = x, up[Adj[e]] = Weight[e];
        dep[Adj[e]] = dep[x] + Weight[e];
        dfs1(Adj[e]);
        size[x] += size[Adj[e]];
        mx[x] = max(mx[x], mx[Adj[e]]);
      }
  }
  int ans[N];
  int vis[N];
  int Fa[21][N];
  void init(int rt) {
    dfs1(rt);
    for (int i = 1; i <= n; i++) a[i] = dep[to[i]];
    Seg.build(1, 1, n);
    for (int i = 1; i <= n; i++) {
      int x = to[Seg.pos[1]];
      ans[i] = ans[i - 1] + Seg.val[1];
      while ((!vis[x]) && x) {
        vis[x] = i;
        Seg.update(1, 1, n, dfn[x], dfn[x] + size[x] - 1, -up[x]);
        x = fa[x];
      }
    }
    for (int i = 1; i <= n; i++) Fa[0][i] = fa[i];
    for (int j = 1; j < 20; j++)
      for (int i = 1; i <= n; i++) Fa[j][i] = Fa[j - 1][Fa[j - 1][i]];
  }
  int query(int x, int y) {
    y = min(y, n);
    if (vis[x] <= y) return ans[y];
    int now = x;
    for (int i = 19; i >= 0; i--)
      if (vis[Fa[i][now]] >= y) now = Fa[i][now];
    now = fa[now];
    int res = mx[x] - dep[now] + ans[y - 1];
    now = x;
    for (int i = 19; i >= 0; i--)
      if (vis[Fa[i][now]] > y) now = Fa[i][now];
    now = fa[now];
    res = max(res, ans[y] - mx[now] + mx[x]);
    return res;
  }
} Tree1, Tree2;
int main() {
  gi(n), gi(m);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    gi(u), gi(v), gi(w);
    addedge(u, v, w);
  }
  get(1, 0, 0);
  int rt1 = now;
  get(rt1, 0, 0);
  int rt2 = now;
  Tree1.init(rt1);
  Tree2.init(rt2);
  int ans = 0;
  while (m--) {
    int x, y;
    gi(x), gi(y);
    x = (x + ans - 1) % n + 1, y = (y + ans - 1) % n + 1;
    print(ans = max(Tree1.query(x, 2 * y - 1), Tree2.query(x, 2 * y - 1)));
    putc('\n');
  }
  return 0;
}
