#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5 + 10;
struct edge {
  long long to;
  long long w;
  long long nxt;
} e[N << 1];
long long n, q, timer, tot;
long long fir[N], sec[N], rev[N], head[N];
long long dis[N], pre[N], cap[N], val[N << 1], lm[N << 1], rm[N << 1],
    res[N << 1], tag[N << 1], M[N << 1];
long long W;
pair<long long, long long> E[N];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline void addedge(long long u, long long v, long long w) {
  ++tot;
  e[tot] = (edge){v, w, head[u]};
  head[u] = tot;
}
inline void DFS(long long u, long long parent) {
  rev[fir[u] = ++timer] = u;
  for (long long i = head[u]; i; i = e[i].nxt) {
    long long v = e[i].to;
    long long w = e[i].w;
    if (v == parent) continue;
    dis[v] = dis[u] + w;
    pre[v] = u;
    cap[v] = w;
    DFS(v, u);
    rev[++timer] = u;
  }
  sec[u] = timer;
}
inline void pushup(long long now) {
  val[now] = max(val[now << 1], val[now << 1 | 1]);
  M[now] = max(M[now << 1], M[now << 1 | 1]);
  lm[now] =
      max(max(lm[now << 1], lm[now << 1 | 1]), val[now << 1] + M[now << 1 | 1]);
  rm[now] =
      max(max(rm[now << 1], rm[now << 1 | 1]), val[now << 1 | 1] + M[now << 1]);
  res[now] = max(
      max(res[now << 1], res[now << 1 | 1]),
      max(lm[now << 1] + val[now << 1 | 1], val[now << 1] + rm[now << 1 | 1]));
}
inline void build(long long now, long long l, long long r) {
  if (l == r) {
    long long x = rev[l];
    tag[now] = 0;
    val[now] = dis[x];
    M[now] = -2 * dis[x];
    lm[now] = rm[now] = -dis[x];
    res[now] = 0;
    return;
  }
  long long mid = (l + r) >> 1;
  build(now << 1, l, mid);
  build(now << 1 | 1, mid + 1, r);
  pushup(now);
}
inline void addtag(long long now, long long x) {
  val[now] += x;
  M[now] -= 2 * x;
  lm[now] -= x;
  rm[now] -= x;
  tag[now] += x;
}
inline void pushdown(long long now) {
  if (tag[now]) {
    addtag(now << 1, tag[now]);
    addtag(now << 1 | 1, tag[now]);
    tag[now] = 0;
  }
}
inline void modify(long long now, long long l, long long r, long long ql,
                   long long qr, long long x) {
  if (l == ql && r == qr) {
    addtag(now, x);
    return;
  }
  pushdown(now);
  long long mid = l + r >> 1;
  if (mid >= qr)
    modify(now << 1, l, mid, ql, qr, x);
  else if (mid + 1 <= ql)
    modify(now << 1 | 1, mid + 1, r, ql, qr, x);
  else {
    modify(now << 1, l, mid, ql, mid, x);
    modify(now << 1 | 1, mid + 1, r, mid + 1, qr, x);
  }
  pushup(now);
}
signed main() {
  read(n);
  read(q);
  read(W);
  for (long long i = 1; i < n; ++i) {
    long long u, v, w;
    read(u);
    read(v);
    read(w);
    addedge(u, v, w);
    addedge(v, u, w);
    E[i] = make_pair(u, v);
  }
  DFS(1, 0);
  build(1, 1, timer);
  long long lastans = 0;
  while (q--) {
    long long x, y;
    read(x);
    read(y);
    long long k = (x + lastans) % (n - 1) + 1;
    long long w = (lastans + y) % W;
    long long X = pre[E[k].first] == E[k].second ? E[k].first : E[k].second;
    modify(1, 1, timer, fir[X], sec[X], w - cap[X]);
    cap[X] = w;
    printf("%lld\n", lastans = res[1]);
  }
  return 0;
}
