#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, inf = 3e18;
char buf[1 << 23], *p1 = buf, *p2 = buf;
int fst[N], nxt[N + N], u[N + N], v[N + N], tot;
int dep[N], n, q;
long long Lw, w[N + N], W[N + N], f[N][2], las;
multiset<long long> s1[N], s2[N];
int c[N][2], fa[N], rev[N];
struct aa {
  long long dt[3][3];
  aa operator*(const aa &b) const {
    aa res;
    for (int i = 0, j, li; i < 3; i++)
      for (j = 0; j < 3; j++)
        for (res.dt[i][j] = -inf, li = 0; li < 3; li++)
          res.dt[i][j] = max(res.dt[i][j], dt[i][li] + b.dt[li][j]);
    return res;
  }
  void init(int id) {
    dt[0][0] = W[id], dt[0][1] = f[id][0] - W[id], dt[2][0] = f[id][0],
    dt[2][1] = f[id][1];
    dt[1][1] = dt[2][2] = 0, dt[0][2] = dt[1][0] = dt[1][2] = -inf;
  }
  long long gt(int fl) {
    long long res = 0;
    for (int j = 0; j <= fl; j++)
      for (int i = 0; i < 3; i++) res = max(res, dt[i][j]);
    return res;
  }
} g[N], G[N];
void add(int lu, int lv, long long lw) {
  u[++tot] = lu, v[tot] = lv, w[tot] = lw, nxt[tot] = fst[lu], fst[lu] = tot;
  u[++tot] = lv, v[tot] = lu, w[tot] = lw, nxt[tot] = fst[lv], fst[lv] = tot;
}
long long read() {
  long long res = 0, fl = 0;
  char a =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (a < '0' || a > '9')
    fl |= a == '-',
        a = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                 ? EOF
                 : *p1++);
  while (a >= '0' && a <= '9')
    res = res * 10 + a - '0',
    a = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  return fl ? -res : res;
}
void work(int x) {
  f[x][0] = f[x][1] = 0;
  if (s1[x].size() > 1) {
    multiset<long long>::iterator it = --s1[x].end();
    f[x][1] += *it, it--, f[x][1] += *it;
  }
  if (s1[x].size())
    f[x][1] = max(f[x][1], *(--s2[x].end())), f[x][0] = *(--s1[x].end()) + W[x];
  else
    f[x][0] = W[x];
  f[x][1] = max(f[x][1], f[x][0]), g[x].init(x);
}
void dfs(int x) {
  for (int i = fst[x]; i; i = nxt[i])
    if (v[i] != fa[x]) {
      fa[v[i]] = x, W[v[i]] = w[i], dep[v[i]] = dep[x] + 1, dfs(v[i]);
      s1[x].insert(f[v[i]][0]), s2[x].insert(f[v[i]][1]);
    }
  work(x);
}
bool nrt(int x) { return c[fa[x]][0] == x || c[fa[x]][1] == x; }
void push_up(int x) { G[x] = G[c[x][1]] * g[x] * G[c[x][0]]; }
void pushr(int x) { swap(c[x][0], c[x][1]), rev[x] ^= 1; }
void push_down(int x) {
  if (rev[x]) pushr(c[x][0]), pushr(c[x][1]), rev[x] = 0;
}
void push_all(int x) {
  if (nrt(x)) push_all(fa[x]);
  push_down(x);
}
void rotate(int x) {
  int y = fa[x], z = fa[y], k = c[y][1] == x, k1 = c[z][1] == y;
  nrt(y) && (c[z][k1] = x), fa[x] = z, c[y][k] = c[x][k ^ 1],
                            fa[c[x][k ^ 1]] = y, c[x][k ^ 1] = y, fa[y] = x,
                            push_up(y), push_up(x);
}
void splay(int x) {
  int y, z, k, k1;
  for (push_all(x); nrt(x); rotate(x))
    y = fa[x], z = fa[y], k = c[y][1] == x, k1 = c[z][1] == y,
    nrt(y) && (k ^ k1 ? rotate(x) : rotate(y), 0);
}
void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) {
    splay(x);
    if (y)
      s1[x].erase(s1[x].find(G[y].gt(0))), s2[x].erase(s2[x].find(G[y].gt(1)));
    if (c[x][1]) s1[x].insert(G[c[x][1]].gt(0)), s2[x].insert(G[c[x][1]].gt(1));
    work(x), c[x][1] = y, push_up(x);
  }
}
int main() {
  int i, j, li;
  for (i = 0; i < 3; i++)
    for (j = 0; j < 3; j++) G[0].dt[i][j] = g[0].dt[i][j] = -inf * (i != j);
  n = read(), q = read(), Lw = read();
  for (i = 1; i < n; i++) j = read(), li = read(), add(j, li, read());
  dep[1] = 1, dfs(1);
  for (i = 1; i <= q; i++) {
    long long la = (read() + las) % (n - 1) + 1, lb = (read() + las) % Lw,
              lc = (dep[u[la * 2]] < dep[v[la * 2]] ? v[la * 2] : u[la * 2]);
    access(lc);
    splay(lc);
    W[lc] = lb, work(lc), push_up(lc), cout << (las = G[lc].gt(1)) << '\n';
  }
  return 0;
}
