#include <bits/stdc++.h>
using namespace std;
inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}
template <typename T>
inline int chkmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline int chkmax(T &a, const T &b) {
  return b > a ? a = b, 1 : 0;
}
template <typename T>
inline T sqr(const T &val) {
  return val * val;
}
namespace fastIO {
const int MAX_BUFFER_SIZE = 1 << 16;
char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;
inline char getc() {
  return *(cur == ed ? ed = buffer + fread(buffer, 1, MAX_BUFFER_SIZE, stdin),
           cur = buffer : cur)++;
}
}  // namespace fastIO
using fastIO::getc;
template <typename T>
inline T read() {
  register T sum(0), fg(1);
  register char ch(getc());
  for (; !isdigit(ch); ch = getc())
    if (ch == '-') fg = -1;
  for (; isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
  return sum * fg;
}
const int MAXN = (int)1e5;
int n, Q;
vector<pair<int, int> > adj[MAXN + 5];
inline void input() {
  n = read<int>(), Q = read<int>();
  for (int i = 1; i < n; ++i) {
    int u = read<int>(), v = read<int>(), w = read<int>();
    adj[u].emplace_back(v, w);
    adj[v].emplace_back(u, w);
  }
}
namespace OT {
int dep[MAXN + 5];
inline void dfs(int u, int fa) {
  for (auto it : adj[u]) {
    int v = it.first;
    if (v != fa) {
      dep[v] = dep[u] + it.second;
      dfs(v, u);
    }
  }
}
inline int get_longest(int S) {
  dep[S] = 0, dfs(S, 0);
  return max_element(dep + 1, dep + n + 1) - dep;
}
}  // namespace OT
inline pair<int, int> find_dia() {
  int A = OT::get_longest(1);
  int B = OT::get_longest(A);
  return make_pair(A, B);
}
const int MAX_LOG = 20;
struct node {
  int val, id;
  node() {}
  node(int _val, int _id) : val(_val), id(_id) {}
};
struct TREE {
  int rt;
  int dep[MAXN + 5], fa[MAXN + 5];
  int anc[MAX_LOG + 1][MAXN + 5];
  int d[MAXN + 5], son[MAXN + 5], D[MAXN + 5];
  inline void dfs(int u, int fa0) {
    dep[u] = dep[fa[u] = fa0] + 1;
    anc[0][u] = fa0;
    for (int i = 1; (1 << i) < dep[u]; ++i)
      anc[i][u] = anc[i - 1][anc[i - 1][u]];
    D[u] = d[u];
    for (auto it : adj[u]) {
      int v = it.first;
      if (v != fa0) {
        d[v] = d[u] + it.second, dfs(v, u);
        if (chkmax(D[u], D[v])) son[u] = v;
      }
    }
  }
  int top[MAXN + 5], leaf[MAXN + 5], val[MAXN + 5];
  inline void dfs_chain(int u, int top0) {
    top[u] = top0;
    val[u] = d[u] - (top0 == rt ? d[rt] : d[fa[top0]]);
    if (son[u]) {
      dfs_chain(son[u], top0);
      leaf[u] = leaf[son[u]];
    } else
      leaf[u] = u;
    for (auto it : adj[u]) {
      int v = it.first;
      if (v != fa[u] && v != son[u]) dfs_chain(v, v);
    }
  }
  node vals[MAXN + 5];
  int M, pre[MAXN + 5];
  int col[MAXN + 5];
  inline void build(int _rt) {
    d[rt = _rt] = 0, dfs(rt, 0);
    dfs_chain(rt, rt);
    M = 0;
    for (int i = 1; i <= n; ++i)
      if (top[i] == i) vals[++M] = node(val[leaf[i]], leaf[i]);
    sort(vals + 1, vals + M + 1, [](node A, node B) { return A.val > B.val; });
    auto color = [&](int u, int c) {
      while (u && !col[u]) col[u] = c, u = fa[u];
    };
    for (int i = 1; i <= M; ++i) {
      pre[i] = pre[i - 1] + vals[i].val;
      color(vals[i].id, i);
    }
  }
  inline int get_nearest(int u, int k) {
    for (int i = MAX_LOG; i >= 0; --i)
      if ((1 << i) < dep[u] && col[anc[i][u]] > k) u = anc[i][u];
    return fa[u];
  }
  inline int query(int p, int k) {
    if (col[p] <= k)
      return pre[min(k, M)];
    else {
      int q = get_nearest(p, k);
      int res = pre[k - 1] + d[leaf[p]] - d[q];
      chkmax(res, pre[k] + d[leaf[p]] - d[leaf[q]]);
      return res;
    }
  }
};
inline void solve() {
  pair<int, int> D = find_dia();
  static TREE A, B;
  A.build(D.first);
  B.build(D.second);
  for (int lst = 0; Q--;) {
    int u = ((read<int>() + lst - 1) % n + n) % n + 1;
    int y = ((read<int>() + lst - 1) % n + n) % n + 1;
    lst = max(A.query(u, 2 * y - 1), B.query(u, 2 * y - 1));
    printf("%d\n", lst);
  }
}
int main() {
  input();
  solve();
  return 0;
}
