#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5 + 7;
struct edge {
  int u, v;
  long long w;
};
vector<edge> ed;
int n, q;
vector<int> gr[maxn];
long long last, w;
int tiktak;
int tin[maxn], tout[maxn];
struct node {
  long long delta;
  long long mndep;
  long long mxdep;
  long long mxlv;
  long long mxvr;
  long long dis;
};
struct T {
  node tree[maxn * 4];
  T() {
    for (int i = 0; i < maxn * 4; i++) {
      tree[i] = {0, 0, 0, 0, 0, 0};
    }
  }
  node shift(node v, long long del) {
    return {v.delta + del, v.mndep + del, v.mxdep + del,
            v.mxlv - del,  v.mxvr - del,  v.dis};
  }
  node gather(node l, node r) {
    node R = shift(r, l.delta);
    node res;
    res.delta = R.delta;
    res.mndep = min(l.mndep, R.mndep);
    res.mxdep = max(l.mxdep, R.mxdep);
    res.mxlv = max(l.mxlv, max(R.mxlv, l.mxdep - 2 * R.mndep));
    res.mxvr = max(l.mxvr, max(R.mxvr, R.mxdep - 2 * l.mndep));
    res.dis = max(l.dis, max(R.dis, max(l.mxlv + R.mxdep, l.mxdep + R.mxvr)));
    return res;
  }
  void upd(int pos, long long val, int v = 1, int tl = 1, int tr = n + n) {
    if (tl == tr) {
      if (val < 0) {
        tree[v] = {val, val, 0, -(val + val), -val, -val};
      } else {
        tree[v] = {val, 0, val, 0, val, val};
      }
      return;
    }
    int mid = (tl + tr) >> 1;
    if (pos <= mid) {
      upd(pos, val, v + v, tl, mid);
    } else {
      upd(pos, val, v + v + 1, mid + 1, tr);
    }
    tree[v] = gather(tree[v + v], tree[v + v + 1]);
  }
};
T tr;
void dfs(int v, int pr) {
  tin[v] = ++tiktak;
  for (int id : gr[v]) {
    int to = ed[id].v + ed[id].u - v;
    if (to == pr) continue;
    dfs(to, v);
  }
  tout[v] = ++tiktak;
}
int main() {
  scanf("%d %d %lld", &n, &q, &w);
  for (int i = 1, u, v; i < n; i++) {
    long long w;
    scanf("%d %d %lld", &u, &v, &w);
    gr[u].push_back(ed.size());
    gr[v].push_back(ed.size());
    ed.push_back({u, v, w});
  }
  dfs(1, 1);
  for (int i = 0; i < ed.size(); i++) {
    int a, b;
    long long w;
    if (tin[ed[i].u] > tin[ed[i].v]) {
      swap(ed[i].u, ed[i].v);
    }
    tie(a, b, w) = make_tuple(ed[i].u, ed[i].v, ed[i].w);
    tr.upd(tin[b], w);
    tr.upd(tout[b], -w);
  }
  while (q--) {
    int d;
    long long e;
    scanf("%d %lld", &d, &e);
    d = (d + last) % (n - 1);
    e = (e + last) % w;
    int a, b;
    tie(a, b) = make_tuple(ed[d].u, ed[d].v);
    ed[d].w = e;
    tr.upd(tin[b], ed[d].w);
    tr.upd(tout[b], -ed[d].w);
    last = tr.tree[1].dis;
    printf("%lld\n", last);
  }
}
