#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, co, fr;
} E[100005 << 1];
int lst[100005], tot;
void addedge(int a, int b, int c) {
  E[++tot] = (edge){b, c, lst[a]};
  lst[a] = tot;
}
int n, q;
int mx, p;
void Getdfs(int v, int f, int di) {
  if (di > mx) mx = di, p = v;
  for (int i = lst[v]; i; i = E[i].fr) {
    int u = E[i].to;
    if (u == f) continue;
    Getdfs(u, v, di + E[i].co);
  }
}
struct Tree {
  int rt, len;
  struct Leaf {
    int id, x;
    bool operator<(const Leaf &_) const { return x > _.x; }
  } A[100005];
  int to[100005], dis[100005];
  int val[100005], fa[100005];
  int sum[100005], ID[100005];
  int top[100005], dep[100005];
  void dfs(int v, int f) {
    bool is = 1;
    to[v] = v;
    dep[v] = dep[f] + 1;
    for (int i = lst[v]; i; i = E[i].fr) {
      int u = E[i].to;
      if (u == f) continue;
      fa[u] = v;
      is = 0;
      dis[u] = dis[v] + E[i].co;
      dfs(u, v);
      if (dis[to[u]] > dis[to[v]]) to[v] = to[u];
    }
    if (is) A[++len] = (Leaf){v, 0};
  }
  void Redfs(int v, int f, int tp, int di) {
    val[v] = di;
    top[v] = v;
    for (int i = lst[v]; i; i = E[i].fr) {
      int u = E[i].to;
      if (u == f) continue;
      if (to[u] == to[v])
        Redfs(u, v, tp, di + E[i].co);
      else
        Redfs(u, v, u, E[i].co);
    }
  }
  void Init() {
    dfs(rt, 0);
    Redfs(rt, 0, rt, 0);
    for (int i = 1; i <= len; i++) A[i].x = val[A[i].id];
    sort(A + 1, A + len + 1);
    for (int i = 1; i <= len; i++)
      sum[i] = sum[i - 1] + A[i].x, ID[A[i].id] = i;
  }
  int Up(int x, int y) {
    while (ID[to[top[x]]] > y) x = fa[top[x]];
    return x;
  }
  int Query(int x, int y) {
    if (y >= len) return sum[len];
    if (ID[to[x]] <= y) return sum[y];
    int ans = sum[y];
    int lca = Up(x, y);
    ans -= min(dis[to[lca]] - dis[lca], A[y].x);
    ans += dis[to[x]] - dis[lca];
    return ans;
  }
} T[2];
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1, a, b, c; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    addedge(a, b, c);
    addedge(b, a, c);
  }
  Getdfs(1, 0, 0);
  T[0].rt = p;
  mx = 0;
  Getdfs(p, 0, 0);
  T[1].rt = p;
  T[0].Init();
  T[1].Init();
  int ans = 0;
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + ans - 1) % n + 1;
    y = (y + ans - 1) % n + 1;
    y = (y << 1) - 1;
    ans = max(T[0].Query(x, y), T[1].Query(x, y));
    printf("%d\n", ans);
  }
  return 0;
}
