#include <bits/stdc++.h>
using namespace std;
inline long long gi() {
  char c = getchar();
  long long x = 0;
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return x;
}
const int N = 2e5 + 5;
const long long inf = -1ll << 60;
int head[N], nxt[N], to[N];
int n, q, u[N], v[N], fa[N], in[N], out[N], id[N], tid;
long long wei[N], w[N], l, dis[N];
struct node {
  long long w1, w2, w12, w21, w, tg;
  node operator+(const long long x) {
    return ((node){w1 + x, w2 - x * 2, w12 - x, w21 - x, w, tg + x});
  }
  node operator+(const node x) {
    node t;
    t.w1 = max(w1, x.w1);
    t.w2 = max(w2, x.w2);
    t.w12 = max(max(w12, x.w12), w1 + x.w2);
    t.w21 = max(max(w21, x.w21), w2 + x.w1);
    t.w = max(max(w, x.w), max(w12 + x.w1, w1 + x.w21));
    return t;
  }
} st[N << 2];
void addedge(int u, int v, long long w, int now) {
  nxt[now] = head[u], head[u] = now, to[now] = v, wei[now] = w;
}
void dfs(int u) {
  id[++tid] = u, in[u] = tid;
  for (int e = head[u]; e; e = nxt[e]) {
    if (to[e] == fa[u]) continue;
    fa[to[e]] = u;
    dis[to[e]] = dis[u] + wei[e];
    dfs(to[e]);
    id[++tid] = u;
  }
  out[u] = tid;
}
void build(int x, int l, int r) {
  if (l == r) {
    st[x] = (node){dis[id[l]], -2ll * dis[id[l]], inf, inf, inf, 0};
    return;
  }
  int mid = l + r >> 1;
  build((x << 1), l, mid), build((x << 1 | 1), mid + 1, r);
  st[x] = st[(x << 1)] + st[(x << 1 | 1)];
}
void pushdown(int x) {
  if (!st[x].tg) return;
  st[(x << 1)] = st[(x << 1)] + st[x].tg,
           st[(x << 1 | 1)] = st[(x << 1 | 1)] + st[x].tg;
  st[x].tg = 0;
}
void update(int x, int l, int r, int sl, int sr, long long w) {
  if (sl <= l && r <= sr) {
    st[x] = st[x] + w;
    return;
  }
  pushdown(x);
  int mid = l + r >> 1;
  if (sl <= mid) update((x << 1), l, mid, sl, sr, w);
  if (sr > mid) update((x << 1 | 1), mid + 1, r, sl, sr, w);
  st[x] = st[(x << 1)] + st[(x << 1 | 1)];
}
int main() {
  n = gi(), q = gi(), l = gi();
  for (int i = 1; i < n; ++i) {
    u[i] = gi(), v[i] = gi(), w[i] = gi();
    addedge(u[i], v[i], w[i], i * 2 - 1);
    addedge(v[i], u[i], w[i], i * 2);
  }
  dfs(1), build(1, 1, n << 1);
  for (int i = 1; i < n; ++i)
    if (fa[v[i]] == u[i]) swap(u[i], v[i]);
  long long lst = 0;
  while (q--) {
    int x = (gi() + lst) % (n - 1) + 1;
    long long e = (gi() + lst) % l;
    update(1, 1, n << 1, in[u[x]], out[u[x]], e - w[x]), w[x] = e;
    printf("%lld\n", lst = st[1].w);
  }
}
