#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e5 + 10;
vector<pair<int, int> > e[SIZE];
vector<pair<int, int> > res;
int len[SIZE], lv[SIZE];
int father[17][SIZE];
int de[SIZE], cs, used[SIZE], root;
int ord[SIZE];
int dfs0(int x) {
  int ma = 0;
  used[x] = cs;
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i].first;
    if (used[y] != cs) {
      len[y] = e[x][i].second;
      lv[y] = lv[x] + len[y];
      father[0][y] = x;
      ma = max(ma, dfs0(y) + e[x][i].second);
    }
  }
  return de[x] = ma;
}
void dfs(int x, int base) {
  used[x] = cs;
  bool flag = 0;
  int i;
  if (x != root && e[x].size() == 1) {
    res.push_back(make_pair(base, x));
    return;
  }
  for (i = 0; i < e[x].size(); i++) {
    int y = e[x][i].first;
    if (used[y] == cs) continue;
    if (de[y] + e[x][i].second < de[x])
      dfs(y, e[x][i].second);
    else {
      if (!flag) {
        dfs(y, base + e[x][i].second);
        flag = 1;
      } else
        dfs(y, e[x][i].second);
    }
  }
}
int dp[SIZE][2], far[SIZE];
void dfs1(int x, int lt) {
  for (int i = 0; i < (((int)(e[x]).size())); ++i) {
    int y = e[x][i].first;
    if (y == lt) continue;
    dfs1(y, x);
    if (dp[y][0] + e[x][i].second > dp[x][0]) {
      dp[x][1] = dp[x][0];
      dp[x][0] = dp[y][0] + e[x][i].second;
    } else if (dp[y][0] + e[x][i].second > dp[x][1]) {
      dp[x][1] = dp[y][0] + e[x][i].second;
    }
  }
}
void dfs2(int x, int lt, int v = 0) {
  far[x] = max(v, dp[x][0]);
  for (int i = 0; i < (((int)(e[x]).size())); ++i) {
    int y = e[x][i].first;
    if (y == lt) continue;
    if (dp[y][0] + e[x][i].second == dp[x][0])
      dfs2(y, x, max(v, dp[x][1]) + e[x][i].second);
    else
      dfs2(y, x, max(v, dp[x][0]) + e[x][i].second);
  }
}
void add(int x, int y, int v) {
  e[x].push_back(make_pair(y, v));
  e[y].push_back(make_pair(x, v));
}
int line[SIZE];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = (1); i < (n); ++i) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    add(x, y, v);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  int root = 1;
  for (int i = (2); i < (n + 1); ++i) {
    if (far[i] < far[root]) root = i;
  }
  cs++;
  dfs0(root);
  cs++;
  dfs(root, 0);
  father[0][root] = root;
  for (int i = (1); i < (17); ++i) {
    for (int j = (1); j < (n + 1); ++j)
      father[i][j] = father[i - 1][father[i - 1][j]];
  }
  sort((res).begin(), (res).end());
  reverse((res).begin(), (res).end());
  ord[root] = 1;
  int all = 0;
  for (int i = 0; i < (((int)(res).size())); ++i) {
    int now = res[i].second;
    line[i / 2 + 1] += res[i].first;
    all += res[i].first;
    while (!ord[now]) {
      ord[now] = i + 1;
      now = father[0][now];
    }
  }
  for (int i = (1); i < (SIZE); ++i) line[i] += line[i - 1];
  memset((dp), 0, sizeof((dp)));
  dfs1(root, root);
  int ans = 0;
  for (int cs = 0; cs < (q); ++cs) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + ans - 1) % n + 1;
    y = (y + ans - 1) % n + 1;
    if (y * 2 >= ((int)(res).size()))
      ans = all;
    else {
      if (y * 2 >= ord[x])
        ans = line[y];
      else {
        int you = x;
        for (int i = 16; i >= 0; i--) {
          if (ord[father[i][you]] > 2 * y) you = father[i][you];
        }
        ans = line[y] + dp[x][0] + lv[x] - lv[you] + len[you];
        ans -= min(res[2 * y - 1].first, dp[father[0][you]][0]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
