#include <bits/stdc++.h>
using namespace std;
const int Maxx = 200005, Maxn = 2001, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
inline long long read() {
  long long res = 0;
  char bj = 0, ch = getchar();
  while (ch < '0' || ch > '9') bj |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9')
    res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
  return bj ? -res : res;
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 ^ 48);
}
inline void printnum(int x, char ch) {
  if (x < 0) putchar('-'), x = -x;
  print(x), putchar(ch);
}
int h[Maxx], to[Maxx << 1], nx[Maxx << 1];
long long vl[Maxx << 1];
int tot, I[Maxx << 1], O[Maxx << 1];
long long d[Maxx], P[Maxx << 1];
inline long long Min(const long long a, const long long b) {
  return a < b ? a : b;
}
inline long long Max(const long long a, const long long b) {
  return a > b ? a : b;
}
struct node {
  long long mi, ma, ml, mr, Ans, lz;
  inline void Pre(const long long x) {
    mi = -2 * x, ma = x, ml = mr = -x, Ans = lz = 0;
  }
  inline void Pr(const long long x) {
    mi -= 2 * x, ma += x, ml -= x, mr -= x, lz += x;
  }
  inline void Merge(const node &lc, const node &rc) {
    Ans = Max(Max(lc.Ans, rc.Ans), Max(lc.ml + rc.ma, rc.mr + lc.ma));
    ml = Max(Max(lc.ml, rc.ml), lc.ma + rc.mi);
    mr = Max(Max(lc.mr, rc.mr), lc.mi + rc.ma);
    mi = Max(lc.mi, rc.mi), ma = Max(lc.ma, rc.ma);
  }
} t[Maxx << 3];
void Dfs(int x, int pr) {
  P[I[pr >> 1] = ++tot] = d[x];
  for (int i = h[x]; i; i = nx[i])
    if (i ^ pr ^ 1) d[to[i]] = d[x] + vl[i], Dfs(to[i], i), P[++tot] = d[x];
  O[pr >> 1] = tot;
}
void Build(int p, int l, int r) {
  if (l == r)
    t[p].Pre(P[l]);
  else {
    int mid = l + r >> 1;
    Build(p << 1, l, mid), Build(p << 1 | 1, mid + 1, r);
    t[p].Merge(t[p << 1], t[p << 1 | 1]);
  }
}
int Ql, Qr;
long long Qx;
inline void Pushdown(int p) {
  if (t[p].lz) t[p << 1].Pr(t[p].lz), t[p << 1 | 1].Pr(t[p].lz), t[p].lz = 0;
}
void Add(int p, int l, int r) {
  if (Ql <= l && r <= Qr)
    t[p].Pr(Qx);
  else {
    int mid = l + r >> 1;
    Pushdown(p);
    if (Ql <= mid) Add(p << 1, l, mid);
    if (Qr > mid) Add(p << 1 | 1, mid + 1, r);
    t[p].Merge(t[p << 1], t[p << 1 | 1]);
  }
}
int main() {
  const int n = read();
  int q = read() + 1;
  const long long W = read();
  for (int i = 1, x, y; i < n; ++i) {
    nx[i << 1] = h[x = read()], to[h[x] = i << 1] = y = read();
    nx[i << 1 | 1] = h[y], to[h[y] = i << 1 | 1] = x;
    vl[i << 1] = vl[i << 1 | 1] = read();
  }
  Dfs(1, 0), Build(1, 1, tot);
  int D;
  long long lst = 0, E;
  while (--q) {
    D = (read() + lst) % (n - 1) + 1, E = (read() + lst) % W;
    Ql = I[D], Qr = O[D], Qx = E - vl[D << 1], vl[D << 1] = E, Add(1, 1, tot);
    printf("%lld\n", lst = t[1].Ans);
  }
  return 0;
}
