#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 2019;
long long c[maxn];
long long st[maxn], ed[maxn], tot, oula[maxn];
long long deep[maxn];
long long dis[maxn];
int dp[maxn][25];
vector<int> g[maxn];
vector<long long> w[maxn];
long long f[maxn];
long long fw[maxn];
struct edge {
  long long u, v, w;
};
edge e[maxn];
long long lowbit(long long x) { return x & (-x); }
void add(long long x, long long d) {
  while (x <= tot) {
    c[x] += d;
    x += lowbit(x);
  }
}
void modify(int l, int r, long long d) {
  add(l, d);
  add(r + 1, -d);
}
long long sum(long long x) {
  long long ans = 0;
  while (x > 0) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
void dfs(int u, int fa, long long d, long long wi) {
  st[u] = ++tot;
  f[u] = fa;
  fw[u] = wi;
  dis[tot] = d;
  oula[tot] = u;
  deep[u] = deep[fa] + 1;
  int len = g[u].size();
  for (int i = 0; i < len; i++) {
    int v = g[u][i];
    if (v == fa) continue;
    dfs(v, u, d + w[u][i], w[u][i]);
    oula[++tot] = u;
  }
  ed[u] = tot;
}
void RMQ_init() {
  for (int i = 1; i <= tot; i++) dp[i][0] = oula[i];
  for (int j = 1; (1 << j) <= tot; j++)
    for (int i = 1; i + (1 << j) - 1 <= tot; i++) {
      if (deep[dp[i][j - 1]] < deep[dp[i + (1 << (j - 1))][j - 1]])
        dp[i][j] = dp[i][j - 1];
      else
        dp[i][j] = dp[i + (1 << (j - 1))][j - 1];
    }
}
int Lca(int l, int r) {
  int k = 0;
  l = st[l];
  r = st[r];
  if (l > r) swap(l, r);
  while (1 << (k + 1) <= r - l + 1) k++;
  if (deep[dp[l][k]] < deep[dp[r - (1 << k) + 1][k]])
    return dp[l][k];
  else
    return dp[r - (1 << k) + 1][k];
}
long long qdis(int u, int v) {
  long long di = sum(st[u]) + sum(st[v]);
  return di - 2 * sum(st[Lca(u, v)]);
}
struct node {
  int u, v;
  long long len;
};
node tr[maxn * 4];
void pushup(int rt) {
  tr[rt] =
      tr[rt << 1].len > tr[rt << 1 | 1].len ? tr[rt << 1] : tr[rt << 1 | 1];
  int x = tr[rt << 1].u, y = tr[rt << 1].v;
  int u = tr[rt << 1 | 1].u, v = tr[rt << 1 | 1].v;
  long long di = 0;
  if ((di = qdis(x, u)) > tr[rt].len) tr[rt] = {x, u, di};
  if ((di = qdis(x, v)) > tr[rt].len) tr[rt] = {x, v, di};
  if ((di = qdis(y, u)) > tr[rt].len) tr[rt] = {y, u, di};
  if ((di = qdis(y, v)) > tr[rt].len) tr[rt] = {y, v, di};
}
void build(int rt, int l, int r) {
  if (l == r) {
    int u = oula[l];
    tr[rt] = {u, u, 0};
    return;
  }
  int mid = (r + l) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  pushup(rt);
}
void update(int rt, int l, int r, int ul, int ur) {
  if (ul <= l && r <= ur) return;
  int mid = (r + l) >> 1;
  if (ul <= mid) update(rt << 1, l, mid, ul, ur);
  if (ur > mid) update(rt << 1 | 1, mid + 1, r, ul, ur);
  pushup(rt);
}
int main() {
  ios::sync_with_stdio(false);
  long long n, q, ww;
  cin >> n >> q >> ww;
  for (int i = 1; i < n; i++) {
    long long u, v, wi;
    cin >> u >> v >> wi;
    g[u].push_back(v);
    w[u].push_back(wi);
    g[v].push_back(u);
    w[v].push_back(wi);
    e[i] = {u, v, wi};
  }
  dfs(1, 0, 0, 0);
  for (int i = 1; i <= n; i++) modify(st[i], ed[i], fw[i]);
  RMQ_init();
  build(1, 1, tot);
  long long last = 0;
  while (q--) {
    long long x, wi;
    cin >> x >> wi;
    x = (x + last) % (n - 1) + 1;
    wi = (wi + last) % ww;
    int u;
    if (f[e[x].v] == e[x].u)
      u = e[x].v;
    else
      u = e[x].u;
    modify(st[u], ed[u], -e[x].w);
    e[x].w = wi;
    modify(st[u], ed[u], e[x].w);
    update(1, 1, tot, st[u], ed[u]);
    cout << (last = tr[1].len) << endl;
  }
}
