#include <bits/stdc++.h>
using namespace std;
int n, q, hd[100000 + 5], len = 0;
long long as = 0;
struct Edge {
  int v, w, net;
} e[2 * 100000 + 5];
void add(int u, int v, int w) {
  e[len] = (Edge){v, w, hd[u]};
  hd[u] = len++;
}
void sort(int ty);
struct Tree {
  int rt, fa[100000 + 5][25], tp[100000 + 5], rk[100000 + 5], son[100000 + 5],
      a[100000 + 5], tot = 0;
  long long sum[100000 + 5], dep[100000 + 5], dis[100000 + 5];
  void dfs(int u, int pre, int wi) {
    fa[u][0] = pre;
    for (int i = (1), en = (20); i <= en; ++i)
      fa[u][i] = fa[fa[u][i - 1]][i - 1];
    for (int i = hd[u]; ~i; i = e[i].net) {
      int v = e[i].v, w = e[i].w;
      if (v == pre) continue;
      dep[v] = dep[u] + w;
      dfs(v, u, w);
      if (dis[u] < dis[v]) dis[u] = dis[v], son[u] = v;
    }
    dis[u] += wi;
  }
  void dfs1(int u, int pre, int top) {
    tp[u] = top;
    if (son[u]) dfs1(son[u], u, top);
    for (int i = hd[u]; ~i; i = e[i].net) {
      int v = e[i].v;
      if (v == pre || v == son[u]) continue;
      a[++tot] = v;
      dfs1(v, u, v);
    }
  }
  long long sol(int x, int y) {
    if (y >= tot)
      return sum[tot];
    else {
      if (rk[tp[x]] <= y)
        return sum[y];
      else {
        int tem = x;
        for (int i = (20), en = (0); i >= en; --i)
          if (rk[tp[fa[tem][i]]] > y) tem = fa[tem][i];
        tem = fa[tem][0];
        return max(sum[y - 1], sum[y] - dis[son[tem]]) + dis[son[x]] + dep[x] -
               dep[tem];
      }
    }
  }
  void init(int ty) {
    tot = 0;
    dfs(rt, 0, 0);
    a[++tot] = rt;
    dfs1(rt, 0, rt);
    sort(ty);
    for (int i = (1), en = (tot); i <= en; ++i)
      rk[a[i]] = i, sum[i] = sum[i - 1] + dis[a[i]];
  }
} tr[2];
template <class T>
void read(T &x) {
  char ch;
  bool ok;
  for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') ok = 1;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (ok) x = -x;
}
bool cmp(int x, int y) { return tr[0].dis[x] > tr[0].dis[y]; }
bool cmp1(int x, int y) { return tr[1].dis[x] > tr[1].dis[y]; }
void sort(int ty) {
  if (!ty)
    sort(tr[ty].a + 1, tr[ty].a + tr[ty].tot + 1, cmp);
  else
    sort(tr[ty].a + 1, tr[ty].a + tr[ty].tot + 1, cmp1);
}
int dis[100000 + 5];
long long dep[100000 + 5];
void dfs(int u, int pre) {
  dis[u] = u;
  for (int i = hd[u]; ~i; i = e[i].net) {
    int v = e[i].v, w = e[i].w;
    if (v == pre) continue;
    dep[v] = dep[u] + w;
    dfs(v, u);
    if (dep[dis[u]] < dep[dis[v]]) dis[u] = dis[v];
  }
}
int main() {
  memset(hd, -1, sizeof hd);
  read(n);
  read(q);
  for (int i = (1), en = (n - 1); i <= en; ++i) {
    int u, v, w;
    read(u);
    read(v);
    read(w);
    add(u, v, w);
    add(v, u, w);
  }
  dfs(1, 0);
  tr[0].rt = dis[1];
  dep[tr[0].rt] = 0;
  dfs(tr[0].rt, 0);
  tr[1].rt = dis[tr[0].rt];
  tr[0].init(0);
  tr[1].init(1);
  while (q--) {
    int x, y;
    read(x);
    read(y);
    x = (x + as - 1) % n + 1;
    y = (y + as - 1) % n + 1;
    as = max(tr[0].sol(x, 2 * y - 1), tr[1].sol(x, 2 * y - 1));
    printf("%lld\n", as);
  }
  return 0;
}
