#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
int n, q, dep[100050], maxdep, root, fa[100050][20], rid[200050], ide[200050],
    mdep[200050], dfs_clock, low[200050], ans[100050], vis[100050], lastans;
vector<int> G[100050], W[100050];
inline void dfs1(int u, int fa) {
  if (dep[u] > maxdep) {
    maxdep = dep[u];
    root = u;
  }
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v != fa) {
      dep[v] = dep[u] + W[u][i];
      dfs1(v, u);
    }
  }
}
inline void dfs2(int u, int fa) {
  ::fa[u][0] = fa;
  ide[u] = ++dfs_clock;
  rid[ide[u]] = u;
  mdep[u] = dep[u];
  for (int i = 1; i < 19; i++) ::fa[u][i] = ::fa[::fa[u][i - 1]][i - 1];
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v != fa) {
      dep[v] = dep[u] + W[u][i];
      dfs2(v, u);
      mdep[u] = max(mdep[u], mdep[v]);
    }
  }
  low[u] = dfs_clock;
}
struct Seg_Tree {
  int l, r;
  int tag;
  pair<int, int> val;
} t[400050];
inline void Push_Up(int id) {
  t[id].val = max(t[id << 1].val, t[id << 1 | 1].val);
}
inline void Build(int id, int l, int r) {
  t[id].l = l;
  t[id].r = r;
  if (l == r) {
    t[id].val = make_pair(dep[rid[l]], rid[l]);
    return;
  }
  int mid = (t[id].l + t[id].r) >> 1;
  Build(id << 1, l, mid);
  Build(id << 1 | 1, mid + 1, r);
  Push_Up(id);
}
inline void Change(int id, int l, int r, int val) {
  if (l <= t[id].l && t[id].r <= r) {
    t[id].val.first += val;
    t[id].tag += val;
    return;
  }
  int mid = (t[id].l + t[id].r) >> 1;
  if (r <= mid)
    Change(id << 1, l, r, val);
  else if (l > mid)
    Change(id << 1 | 1, l, r, val);
  else {
    Change(id << 1, l, mid, val);
    Change(id << 1 | 1, mid + 1, r, val);
  }
  Push_Up(id);
  t[id].val.first += t[id].tag;
}
int main() {
  n = read(), q = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read(), w = read();
    G[u].push_back(v);
    G[v].push_back(u);
    W[u].push_back(w);
    W[v].push_back(w);
  }
  dfs1(1, 0);
  memset(dep, 0, sizeof(dep));
  dfs2(root, 0);
  Build(1, 1, n);
  for (int i = 2; i <= n; i++) {
    ans[i] = ans[i - 1] + t[1].val.first;
    for (int j = t[1].val.second; j && !vis[j]; j = fa[j][0]) {
      vis[j] = i;
      Change(1, ide[j], low[j], dep[fa[j][0]] - dep[j]);
    }
  }
  while (q--) {
    int u = read(), v = read();
    u = (u + lastans - 1) % n + 1;
    v = (v + lastans - 1) % n + 1;
    v *= 2;
    v = min(v, n);
    if (vis[u] <= v)
      lastans = ans[v];
    else {
      int x = u;
      for (int i = 18; i >= 0; i--) {
        if (vis[fa[u][i]] > v) u = fa[u][i];
      }
      u = fa[u][0];
      lastans = ans[v] + mdep[x] - dep[u] -
                min(dep[u], min(ans[v] - ans[v - 1], mdep[u] - dep[u]));
    }
    cout << lastans << endl;
  }
  return 0;
}
