#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m, head[maxn], tot;
struct node {
  int to, next, val;
} e[maxn << 1];
inline void addedge(int x, int y, int w) {
  e[++tot] = (node){y, head[x], w}, head[x] = tot;
}
struct Tree {
  int dis[maxn], len[maxn], son[maxn], rnk[maxn], sum[maxn], f[maxn][18],
      g[maxn][18], rt, cnt;
  pair<int, int> s[maxn];
  void dfs1(int x, int ff) {
    for (int i = head[x], y = e[i].to, w = e[i].val; i;
         i = e[i].next, y = e[i].to, w = e[i].val)
      if (y != ff) dis[y] = dis[x] + w, dfs1(y, x);
  }
  void dfs2(int x, int ff) {
    for (int i = head[x], y = e[i].to, w = e[i].val; i;
         i = e[i].next, y = e[i].to, w = e[i].val)
      if (y != ff) {
        f[y][0] = x, g[y][0] = w;
        for (int i = 1; i <= 17; i++)
          f[y][i] = f[f[y][i - 1]][i - 1],
          g[y][i] = g[y][i - 1] + g[f[y][i - 1]][i - 1];
        dfs2(y, x);
        if (len[y] + w > len[x]) len[x] = len[y] + w, son[x] = y;
      }
    for (int i = head[x], y = e[i].to, w = e[i].val; i;
         i = e[i].next, y = e[i].to, w = e[i].val)
      if (y != ff && y != son[x]) s[++cnt] = pair<int, int>(-len[y] - w, y);
  }
  inline void init(int root) {
    dfs1(root, 0);
    for (int i = 1; i <= n; i++)
      if (!rt || dis[i] > dis[rt]) rt = i;
    dfs2(rt, 0);
    s[++cnt] = pair<int, int>(-len[rt], rt);
    sort(s + 1, s + cnt + 1);
    for (int i = 1; i <= cnt; i++) {
      int x = s[i].second;
      while (x) rnk[x] = i, x = son[x];
      sum[i] = sum[i - 1] - s[i].first;
    }
  }
  inline int solve1(int x, int y) {
    int z = len[x];
    for (int i = 17; i >= 0; i--)
      if (rnk[f[x][i]] >= y) z += g[x][i], x = f[x][i];
    return sum[y - 1] + z + g[x][0];
  }
  inline int solve2(int x, int y) {
    int z = len[x];
    for (int i = 17; i >= 0; i--)
      if (rnk[f[x][i]] > y) z += g[x][i], x = f[x][i];
    return sum[y] - len[f[x][0]] + z + g[x][0];
  }
  inline int query(int x, int y) {
    y = 2 * y - 1;
    return (y > cnt)       ? sum[cnt]
           : (rnk[x] <= y) ? sum[y]
                           : max(solve1(x, y), solve2(x, y));
  }
} T[2];
int main() {
  scanf("%d%d", &n, &m);
  int x, y, w, lastans = 0;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &w);
    addedge(x, y, w), addedge(y, x, w);
  }
  T[0].init(1), T[1].init(T[0].rt);
  while (m--) {
    scanf("%d%d", &x, &y);
    x = (x + lastans - 1) % n + 1, y = (y + lastans - 1) % n + 1;
    printf("%d\n", lastans = max(T[0].query(x, y), T[1].query(x, y)));
  }
  return 0;
}
