#include <bits/stdc++.h>
struct Side {
  int to;
  int length;
  int next;
  Side() { to = length = next = 0; }
  Side(int a, int b, int c) {
    to = a;
    length = b;
    next = c;
  }
};
int n, q, s, k;
int a, b;
int lastans = 0;
int dis[100001];
int sidecnt = 1;
int head[100001];
Side sides[100001 << 1];
void inline adde(int x, int y, int z, bool repeat = true) {
  sides[++sidecnt] = Side(y, z, head[x]);
  head[x] = sidecnt;
  if (repeat) {
    adde(y, x, z, false);
  }
}
void dfs(int x, int father) {
  int cnt = 0;
  int next = head[x];
  while (next != 0) {
    int y = sides[next].to;
    if (y != father) {
      cnt++;
      dis[y] = dis[x] + sides[next].length;
      dfs(y, x);
    }
    next = sides[next].next;
  }
  if (cnt == 0) {
    k++;
  }
}
struct Tree {
  int longson[100001];
  int length[100001];
  int top[100001];
  int fa[100001][21];
  int g[100001][21];
  int t = 0;
  int s[100001];
  int l[100001];
  int r[100001];
  int rnk[100001];
  void cut(int x, int father) {
    fa[x][0] = father;
    for (int i = 1; i <= 20; i++) {
      fa[x][i] = fa[fa[x][i - 1]][i - 1];
      g[x][i] = g[x][i - 1] + g[fa[x][i - 1]][i - 1];
    }
    int next = head[x];
    while (next != 0) {
      int y = sides[next].to;
      if (y != father) {
        g[y][0] = sides[next].length;
        cut(y, x);
        if (sides[next].length + length[y] > length[x]) {
          length[x] = sides[next].length + length[y];
          longson[x] = y;
        }
      }
      next = sides[next].next;
    }
  }
  void inf(int x, int topfather) {
    top[x] = topfather;
    if (!longson[x]) {
      return;
    }
    inf(longson[x], topfather);
    int next = head[x];
    while (next != 0) {
      int y = sides[next].to;
      if (y != fa[x][0] && y != longson[x]) {
        inf(y, y);
      }
      next = sides[next].next;
    }
  }
  bool inline cmp(int left, int right) { return s[left] > s[right]; }
  void init() {
    for (int i = 1; i <= n; i++) {
      if (top[i] == i) {
        l[++t] = i;
        s[i] = length[i] + g[i][0];
      }
    }
    std::sort(l + 1, l + t + 1,
              std::bind(&Tree::cmp, this, std::placeholders::_1,
                        std::placeholders::_2));
    for (int i = 1; i <= t; i++) {
      r[i] = r[i - 1] + s[l[i]];
    }
    for (int i = 1; i <= t; i++) {
      int x = l[i];
      while (x) {
        rnk[x] = i;
        x = longson[x];
      }
    }
  }
  int plan1(int x, int y) {
    int z = length[x];
    for (int i = 20; i >= 0; i--) {
      if (rnk[fa[x][i]] >= y) {
        z += g[x][i];
        x = fa[x][i];
      }
    }
    return r[y - 1] + z + g[x][0];
  }
  int plan2(int x, int y) {
    int z = length[x];
    for (int i = 20; i >= 0; i--) {
      if (rnk[fa[x][i]] > y) {
        z += g[x][i];
        x = fa[x][i];
      }
    }
    return r[y] - length[fa[x][0]] + z + g[x][0];
  }
  int ask(int x, int y) {
    y = 2 * y - 1;
    return rnk[x] <= y ? r[y] : std::max(plan1(x, y), plan2(x, y));
  }
};
Tree t1, t2;
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    adde(x, y, z);
    s += z;
  }
  dis[1] = 0;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if (dis[i] > dis[a]) {
      a = i;
    }
  }
  dis[a] = 0;
  dfs(a, 0);
  for (int i = 1; i <= n; i++) {
    if (dis[i] > dis[b]) {
      b = i;
    }
  }
  k = (k >> 1) + 1;
  t1.cut(a, 0);
  t1.inf(a, a);
  t1.init();
  t2.cut(b, 0);
  t2.inf(b, b);
  t2.init();
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + lastans - 1) % n + 1;
    y = (y + lastans - 1) % n + 1;
    lastans = (2 * y >= k ? s : std::max(t1.ask(x, y), t2.ask(x, y)));
    printf("%d\n", lastans);
  }
  return 0;
}
