#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 5;
int n, Q, mx, pos, A, B;
struct Edge {
  int to, dis;
  Edge *nxt;
  Edge(int to = 0, int dis = 0, Edge *nxt = NULL)
      : to(to), dis(dis), nxt(nxt) {}
} * head[N], pool[N << 1], *tail = pool;
inline void add(int u, int v, int w) {
  head[u] = new (tail++) Edge(v, w, head[u]);
}
void dfs(int x, int fa, int d) {
  if (d > mx) mx = d, pos = x;
  for (Edge *i = head[x]; i; i = i->nxt) {
    int to = i->to;
    if (to == fa) continue;
    dfs(to, x, d + i->dis);
  }
}
struct Tree {
  int fa[N][20], dis[N], dfn[N], id[N], ans[N], vis[N], size[N], mx[N];
  int cnt;
  void dfs(int x) {
    dfn[x] = ++cnt;
    id[cnt] = x;
    size[x] = 1;
    mx[x] = dis[x];
    for (int i = 1; i <= 19; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
    for (Edge *i = head[x]; i; i = i->nxt) {
      int to = i->to;
      if (to == fa[x][0]) continue;
      dis[to] = dis[x] + i->dis;
      fa[to][0] = x;
      dfs(to);
      size[x] += size[to];
      mx[x] = max(mx[x], mx[to]);
    }
  }
  struct node {
    node *ls, *rs;
    int l, r, tag;
    pair<int, int> p;
    node(int l = 0, int r = 0) : l(l), r(r) {
      ls = rs = NULL;
      tag = 0;
      p = make_pair(0, 0);
    }
    inline void up() { p = max(ls->p, rs->p); }
    inline void add(int k) {
      p.first += k;
      tag += k;
    }
    inline void down() {
      if (tag) {
        ls->add(tag);
        rs->add(tag);
        tag = 0;
      }
    }
    void chenge(int x, int y, int k) {
      if (x <= l && r <= y) return (void)(add(k));
      int mid = (l + r) >> 1;
      down();
      if (x <= mid) ls->chenge(x, y, k);
      if (y > mid) rs->chenge(x, y, k);
      up();
    }
  } * root, pool[N << 1], *tail = pool;
  void build(node *&o, int l, int r) {
    o = new (tail++) node(l, r);
    if (l == r) return (void)(o->p = make_pair(dis[id[l]], id[l]));
    int mid = (l + r) >> 1;
    build(o->ls, l, mid);
    build(o->rs, mid + 1, r);
    o->up();
  }
  void pre() {
    for (int i = 1, x; i <= n; i++) {
      x = root->p.second;
      ans[i] = ans[i - 1] + root->p.first;
      while (!vis[x] && x) {
        root->chenge(dfn[x], dfn[x] + size[x] - 1, dis[fa[x][0]] - dis[x]);
        vis[x] = i;
        x = fa[x][0];
      }
    }
  }
  inline int query(int x, int y) {
    y = min(y, n);
    if (vis[x] <= y) return ans[y];
    int u = x, res = 0;
    for (int i = 19; ~i; i--)
      if (vis[fa[u][i]] >= y) u = fa[u][i];
    u = fa[u][0];
    res = ans[y - 1] - dis[u] + mx[x];
    u = x;
    for (int i = 19; ~i; i--)
      if (vis[fa[u][i]] > y) u = fa[u][i];
    u = fa[u][0];
    res = max(res, ans[y] - mx[u] + mx[x]);
    return res;
  }
} T1, T2;
int main() {
  n = read();
  Q = read();
  int ans = 0;
  for (int i = 1, u, v, w; i < n; i++)
    u = read(), v = read(), w = read(), add(u, v, w), add(v, u, w);
  dfs(1, 0, 0);
  A = pos;
  mx = 0;
  dfs(A, 0, 0);
  B = pos;
  T1.dfs(A);
  T1.build(T1.root, 1, n);
  T1.pre();
  T2.dfs(B);
  T2.build(T2.root, 1, n);
  T2.pre();
  while (Q-- > 0) {
    int x = (read() + ans - 1) % n + 1, y = (read() + ans - 1) % n + 1;
    y = 2 * y - 1;
    printf("%d\n", ans = max(T1.query(x, y), T2.query(x, y)));
  }
}
