#include <bits/stdc++.h>
const int MAXN = 200005;
const long long INF = (long long)1e9 + 5;
const long long MOD = 998244353;
using namespace std;
struct Segment_tree {
  long long dia[4 * MAXN], maxL[4 * MAXN], maxR[4 * MAXN], maxv[4 * MAXN],
      minv[4 * MAXN], add[4 * MAXN];
  void pull(int idx, int len) {
    int l = idx << 1, r = idx << 1 | 1;
    dia[idx] = max({dia[l], dia[r], maxL[l] + maxv[r], maxR[r] + maxv[l]});
    maxL[idx] = max({maxL[l], maxL[r], maxv[l] - 2 * minv[r]}) - add[idx];
    maxR[idx] = max({maxR[l], maxR[r], maxv[r] - 2 * minv[l]}) - add[idx];
    maxv[idx] = max(maxv[l], maxv[r]) + add[idx];
    minv[idx] = min(minv[l], minv[r]) + add[idx];
  }
  void init(vector<long long> &depth, int l, int r, int idx) {
    if (l == r) {
      dia[idx] = 0;
      maxL[idx] = maxR[idx] = -depth[l];
      maxv[idx] = minv[idx] = depth[l];
      return;
    }
    int m = (l + r) >> 1;
    init(depth, l, m, idx << 1);
    init(depth, m + 1, r, idx << 1 | 1);
    pull(idx, r - l + 1);
  }
  void range_add(int ql, int qr, long long w, int l, int r, int idx) {
    if (ql <= l && r <= qr) {
      maxL[idx] -= w;
      maxR[idx] -= w;
      maxv[idx] += w;
      minv[idx] += w;
      add[idx] += w;
      return;
    }
    int m = (l + r) >> 1;
    if (ql <= m) range_add(ql, qr, w, l, m, idx << 1);
    if (qr > m) range_add(ql, qr, w, m + 1, r, idx << 1 | 1);
    pull(idx, r - l + 1);
  }
} tree;
struct Edge {
  int to;
  long long w;
  int id;
};
int N, M, Q;
long long W;
long long wei[MAXN], last;
int son[MAXN];
int st[MAXN], ed[MAXN], pa[MAXN];
vector<int> tour;
vector<long long> depth;
vector<Edge> G[MAXN];
void dfs(int v, int p, long long d) {
  st[v] = tour.size();
  depth.push_back(d);
  tour.push_back(v);
  for (Edge &e : G[v]) {
    if (e.to == p) continue;
    son[e.id] = e.to;
    dfs(e.to, v, d + e.w);
    depth.push_back(d);
    tour.push_back(v);
  }
  ed[v] = tour.size() - 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> N >> Q >> W;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    wei[i] = c;
    G[a].push_back({b, c, i});
    G[b].push_back({a, c, i});
  }
  tour.push_back(-1);
  depth.push_back(-1);
  dfs(1, 1, 0);
  M = tour.size() - 1;
  tree.init(depth, 1, M, 1);
  while (Q--) {
    long long d, e;
    cin >> d >> e;
    d = (d + last) % (N - 1);
    e = (e + last) % W;
    tree.range_add(st[son[d]], ed[son[d]], e - wei[d], 1, M, 1);
    wei[d] = e;
    last = tree.dia[1];
    cout << last << '\n';
  }
}
