#include <bits/stdc++.h>
using namespace std;
const int N = 223456;
int n, q;
vector<pair<int, long long>> adj[N];
long long depths[N];
long long tree[N << 2][6];
long long lazy[N << 2];
void Merge(int i, int l, int r) {
  int lc = i * 2, rc = i * 2 + 1;
  tree[i][0] = max(tree[lc][0], tree[rc][0]);
  tree[i][1] =
      max(tree[lc][1], max(tree[rc][1], tree[lc][0] + 2 * tree[rc][5]));
  tree[i][2] =
      max(tree[lc][2], max(tree[rc][2], max(tree[lc][1] + tree[rc][4],
                                            tree[lc][0] + tree[rc][3])));
  tree[i][3] =
      max(tree[lc][3], max(tree[rc][3], 2LL * tree[lc][5] + tree[rc][4]));
  tree[i][4] = max(tree[lc][4], tree[rc][4]);
  tree[i][5] = max(tree[lc][5], tree[rc][5]);
}
void Build(int i, int l, int r) {
  if (l == r) {
    tree[i][0] = depths[l];
    tree[i][1] = -depths[l];
    tree[i][2] = 0;
    tree[i][3] = -depths[l];
    tree[i][4] = depths[l];
    tree[i][5] = -depths[l];
    return;
  }
  int mid = (l + r) >> 1;
  Build(i * 2, l, mid);
  Build(i * 2 + 1, mid + 1, r);
  Merge(i, l, r);
}
void Push(int i, int l, int r) {
  if (lazy[i] != 0) {
    tree[i][0] += lazy[i];
    tree[i][1] -= lazy[i];
    tree[i][3] -= lazy[i];
    tree[i][4] += lazy[i];
    tree[i][5] -= lazy[i];
    if (l != r) {
      lazy[i * 2] += lazy[i];
      lazy[i * 2 + 1] += lazy[i];
    }
    lazy[i] = 0;
  }
}
void Update(int i, int l, int r, int qs, int qe, long long delta) {
  Push(i, l, r);
  if (l > qe || r < qs) {
    return;
  }
  if (l >= qs and r <= qe) {
    lazy[i] += delta;
    Push(i, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  Update(i * 2, l, mid, qs, qe, delta);
  Update(i * 2 + 1, mid + 1, r, qs, qe, delta);
  Merge(i, l, r);
}
int ticks;
int height[N];
int st[N], en[N];
int a[N], b[N];
long long weights[N];
void Dfs(int u, int p) {
  for (auto [v, w] : adj[u]) {
    if (v != p) {
      depths[1 + ticks] = depths[ticks] + w;
      ++ticks;
      st[v] = ticks;
      height[v] = height[u] + 1;
      Dfs(v, u);
      depths[1 + ticks] = depths[ticks] - w;
      ++ticks;
      en[v] = ticks;
    }
  }
}
int main() {
  ios ::sync_with_stdio(false);
  long long W;
  cin >> n >> q >> W;
  for (int i = 1; i < n; i++) {
    cin >> a[i] >> b[i] >> weights[i];
    adj[a[i]].push_back({b[i], weights[i]});
    adj[b[i]].push_back({a[i], weights[i]});
  }
  Dfs(1, 1);
  Build(1, 1, 2 * n - 2);
  long long last = 0;
  while (q--) {
    long long dj, ej;
    cin >> dj >> ej;
    dj = (dj + last) % (n - 1);
    dj++;
    ej = (ej + last) % W;
    int u = a[dj], v = b[dj];
    if (height[u] > height[v]) swap(u, v);
    Update(1, 1, 2 * n - 2, st[v], en[v] - 1, ej - weights[dj]);
    weights[dj] = ej;
    last = tree[1][2];
    cout << last << '\n';
  }
}
