#include <bits/stdc++.h>
using namespace std;
int N, Q;
long long KK;
int lnk[100005];
int pre[200005], tgt[200005], cnt;
long long val[200005];
int pos[100005];
long long Val[100005];
void add_E(int u, int v, long long c) {
  pre[++cnt] = lnk[u], tgt[cnt] = v, val[cnt] = c, lnk[u] = cnt;
}
long long dep[100005];
int Tin[100005], Tout[100005];
int dfn[200005], idx;
void dfs(int x, int f) {
  dfn[++idx] = x;
  Tin[x] = idx;
  for (int e = lnk[x]; e; e = pre[e])
    if (tgt[e] != f)
      pos[(e + 1) >> 1] = tgt[e], dep[tgt[e]] = dep[x] + val[e], dfs(tgt[e], x),
                     dfn[++idx] = x;
  Tout[x] = idx;
}
long long W[800005], M[800005], LM[800005], MR[800005], LMR[800005],
    Lzy[800005];
void push_up(int x) {
  W[x] = max(W[x << 1], W[x << 1 | 1]);
  M[x] = max(M[x << 1], M[x << 1 | 1]);
  LM[x] = max(max(LM[x << 1], LM[x << 1 | 1]), W[x << 1] + M[x << 1 | 1]);
  MR[x] = max(max(MR[x << 1], MR[x << 1 | 1]), M[x << 1] + W[x << 1 | 1]);
  LMR[x] = max(max(LMR[x << 1], LMR[x << 1 | 1]),
               max(LM[x << 1] + W[x << 1 | 1], W[x << 1] + MR[x << 1 | 1]));
}
void Add(int x, int l, int r, long long K) {
  W[x] += K;
  M[x] -= 2 * K;
  LM[x] -= K;
  MR[x] -= K;
  Lzy[x] += K;
}
void push_down(int x, int l, int r) {
  int mid = (l + r) >> 1;
  Add(x << 1, l, mid, Lzy[x]);
  Add(x << 1 | 1, mid + 1, r, Lzy[x]);
  Lzy[x] = 0;
}
void Build(int x, int l, int r) {
  if (l == r) {
    W[x] = dep[dfn[l]];
    M[x] = -2 * dep[dfn[l]];
    LM[x] = MR[x] = -dep[dfn[l]];
    LMR[x] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  Build(x << 1, l, mid);
  Build(x << 1 | 1, mid + 1, r);
  push_up(x);
}
void Update(int x, int l, int r, int L, int R, long long K) {
  if (L <= l && r <= R) {
    Add(x, l, r, K);
    return;
  }
  int mid = (l + r) >> 1;
  push_down(x, l, r);
  if (L <= mid) Update(x << 1, l, mid, L, R, K);
  if (R > mid) Update(x << 1 | 1, mid + 1, r, L, R, K);
  push_up(x);
}
long long lstans;
int main() {
  scanf("%d%d%lld", &N, &Q, &KK);
  for (int i = 1; i < N; i++) {
    int u, v;
    scanf("%d%d%lld", &u, &v, &Val[i]);
    add_E(u, v, Val[i]);
    add_E(v, u, Val[i]);
  }
  dfs(1, 0);
  Build(1, 1, idx);
  while (Q--) {
    int d;
    long long K;
    scanf("%d%lld", &d, &K);
    d = (d + lstans % (N - 1)) % (N - 1) + 1;
    K = (K + lstans % KK) % KK;
    Update(1, 1, idx, Tin[pos[d]], Tout[pos[d]], K - Val[d]);
    Val[d] = K;
    printf("%lld\n", lstans = LMR[1]);
  }
}
