#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void in(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) f |= (c == '-'), c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ '0'), c = getchar();
  f ? x = -x : 0;
}
template <class T>
inline void out(T x, const char c = '\n') {
  static short st[30];
  short m = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++m] = x % 10, x /= 10;
  while (x);
  while (m) putchar(st[m--] | '0');
  putchar(c);
}
template <class T, class... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
template <class T, class... Args>
inline void out(const T &x, const Args &...args) {
  out(x, ' ');
  out(args...);
}
template <class T>
inline void prt(T a[], int n) {
  for (register int i = 0; i < n; ++i) out(a[i], ' ');
  putchar('\n');
}
template <class T>
inline void clr(T a[], int n) {
  memset(a, 0, sizeof(T) * n);
}
template <class T>
inline void clr(T *a, T *b) {
  memset(a, 0, sizeof(T) * (b - a));
}
template <class T>
inline bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool ckmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
namespace MOD_CALC {
const int md = 1e9 + 7, inv2 = (md + 1) / 2;
inline int add(const int a, const int b) {
  return a + b >= md ? a + b - md : a + b;
}
inline int sub(const int a, const int b) {
  return a - b < 0 ? a - b + md : a - b;
}
inline int mul(const int a, const int b) { return (long long)a * b % md; }
inline void inc(int &a, const int b) { (a += b) >= md ? a -= md : 0; }
inline void dec(int &a, const int b) { (a -= b) < 0 ? a += md : 0; }
inline int qpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1) r = mul(r, a);
  return r;
}
inline int qpow(int a, int b, const int p) {
  int r = 1;
  for (; b; b >>= 1, a = (long long)a * a % p)
    if (b & 1) r = (long long)r * a % p;
  return r;
}
inline int mdinv(const int a) { return qpow(a, md - 2); }
template <class... Args>
inline int add(const int a, const int b, const Args &...args) {
  return add(add(a, b), args...);
}
template <class... Args>
inline int mul(const int a, const int b, const Args &...args) {
  return mul(mul(a, b), args...);
}
}  // namespace MOD_CALC
using namespace MOD_CALC;
namespace i207M {
int n;
vector<pair<int, int> > E[100005];
struct Solve {
  int rt;
  int fa[100005][17], dep[100005], far[100005];
  void dfs(int x, int _fa) {
    fa[x][0] = _fa;
    for (register int i = 1; i <= 16 && fa[x][i - 1]; ++i)
      fa[x][i] = fa[fa[x][i - 1]][i - 1];
    far[x] = x;
    for (const auto &it : E[x]) {
      int v = it.first, w = it.second;
      if (v == _fa) continue;
      dep[v] = dep[x] + w, dfs(v, x);
      if (dep[far[v]] > dep[far[x]]) far[x] = far[v];
    }
  }
  int val[100005], lef[100005], cnt;
  void efs(int x, int _tp) {
    for (const auto &it : E[x]) {
      int v = it.first;
      if (v == fa[x][0]) continue;
      if (far[v] == far[x])
        efs(v, _tp);
      else
        efs(v, v), val[lef[++cnt] = far[v]] = dep[far[v]] - dep[x];
    }
  }
  int rk[100005], sum[100005];
  void prework() {
    dfs(rt, 0);
    efs(rt, rt), val[lef[++cnt] = far[rt]] = dep[far[rt]];
    sort(lef + 1, lef + 1 + cnt,
         [&](const int a, const int b) { return val[a] > val[b]; });
    for (register int i = 1; i <= cnt; ++i)
      rk[lef[i]] = i, sum[i] = sum[i - 1] + val[lef[i]];
  }
  int solve(int x, int y) {
    if (y >= cnt) return sum[cnt];
    if (rk[far[x]] <= y) return sum[y];
    int t = dep[far[x]];
    for (register int i = 16; i >= 0; --i)
      if (fa[x][i] && rk[far[fa[x][i]]] > y) x = fa[x][i];
    x = fa[x][0];
    return sum[y] + t - dep[x] - min(dep[far[x]] - dep[x], val[lef[y]]);
  }
} A, B;
int mx, mxk;
void dfs(int x, int _fa, int d) {
  if (ckmax(mx, d)) mxk = x;
  for (const auto &it : E[x]) {
    int v = it.first, w = it.second;
    if (v == _fa) continue;
    dfs(v, x, d + w);
  }
}
void getcross() {
  dfs(1, 0, 0);
  A.rt = mxk;
  mx = 0, dfs(mxk, 0, 0);
  B.rt = mxk;
}
signed main() {
  int cq, ans = 0, x, y;
  in(n, cq);
  for (register int i = 1, a, b, c; i < n; ++i) {
    in(a, b, c);
    E[a].push_back(make_pair(b, c)), E[b].push_back(make_pair(a, c));
  }
  getcross();
  A.prework(), B.prework();
  while (cq--) {
    in(x, y);
    x = (x + ans - 1) % n + 1, y = (y + ans - 1) % n + 1;
    y = y * 2 - 1;
    ans = max(A.solve(x, y), B.solve(x, y));
    out(ans);
  }
  return 0;
}
}  // namespace i207M
signed main() {
  i207M::main();
  return 0;
}
