#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
  register T f = 1;
  register char ch = getchar();
  t = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  t *= f;
  return t;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const long long p = 998244353;
inline long long power(register long long x, register long long k) {
  register long long re = 1;
  for (; k; k >>= 1, x = (x * x) % p)
    if (k & 1) re = (re * x) % p;
  return re;
}
int head[100005], ne[200005], to[200005], total = 1;
long long fare[200005];
inline void add(int a, int b, long long c) {
  total++;
  to[total] = b;
  ne[total] = head[a];
  head[a] = total;
  fare[total] = c;
}
namespace T1 {
long long depth[100005];
int deep[100005];
int size[100005];
int id[100005], id_top;
int idf[100005];
int fa[100005], son[100005];
int top[100005];
void dfs1(int now) {
  size[now] = 1;
  deep[now] = deep[fa[now]] + 1;
  for (int i = head[now]; i; i = ne[i])
    if (to[i] != fa[now]) {
      depth[to[i]] = depth[now] + fare[i];
      fa[to[i]] = now;
      dfs1(to[i]);
      if (size[to[i]] >= size[son[now]]) son[now] = to[i];
      size[now] += size[to[i]];
    }
}
void dfs2(int now, int topf) {
  id[now] = ++id_top;
  top[now] = topf;
  if (son[now]) dfs2(son[now], topf);
  for (int i = head[now]; i; i = ne[i])
    if (to[i] != fa[now] && to[i] != son[now]) dfs2(to[i], to[i]);
}
inline int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (deep[top[x]] < deep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  if (deep[x] < deep[y]) return x;
  return y;
}
struct BIT {
  long long c[100005];
  inline void add(int x, long long val) {
    for (; x <= 100000; x += (x & (-x))) c[x] += val;
  }
  inline long long ask(int x) {
    long long re = 0;
    for (; x; x -= (x & (-x))) re += c[x];
    return re;
  }
} dep;
inline long long Dis(int x, int y) {
  int lc = lca(x, y);
  return dep.ask(id[x]) + dep.ask(id[y]) - dep.ask(id[lc]) * 2;
}
}  // namespace T1
namespace T2 {
struct SGT {
  int lcs, rcs;
  long long dist;
  int xp, yp;
} v[200005];
int tot = 0;
void push_up(int l, int r, int p) {
  if (v[v[p].lcs].dist > v[v[p].rcs].dist) {
    v[p].xp = v[v[p].lcs].xp;
    v[p].yp = v[v[p].lcs].yp;
    v[p].dist = v[v[p].lcs].dist;
  } else {
    v[p].xp = v[v[p].rcs].xp;
    v[p].yp = v[v[p].rcs].yp;
    v[p].dist = v[v[p].rcs].dist;
  }
  long long di;
  di = T1::Dis(v[v[p].lcs].xp, v[v[p].rcs].yp);
  if (di > v[p].dist) {
    v[p].dist = di;
    v[p].xp = v[v[p].lcs].xp;
    v[p].yp = v[v[p].rcs].yp;
  }
  di = T1::Dis(v[v[p].lcs].yp, v[v[p].rcs].xp);
  if (di > v[p].dist) {
    v[p].dist = di;
    v[p].xp = v[v[p].lcs].yp;
    v[p].yp = v[v[p].rcs].xp;
  }
  di = T1::Dis(v[v[p].lcs].xp, v[v[p].rcs].xp);
  if (di > v[p].dist) {
    v[p].dist = di;
    v[p].xp = v[v[p].lcs].xp;
    v[p].yp = v[v[p].rcs].xp;
  }
  di = T1::Dis(v[v[p].lcs].yp, v[v[p].rcs].yp);
  if (di > v[p].dist) {
    v[p].dist = di;
    v[p].xp = v[v[p].lcs].yp;
    v[p].yp = v[v[p].rcs].yp;
  }
}
void build(int l, int r, int& p) {
  p = ++tot;
  if (l == r) {
    v[p].xp = v[p].yp = T1::idf[l];
    v[p].dist = 0;
    return;
  }
  build(l, ((l + r) >> 1), v[p].lcs);
  build(((l + r) >> 1) + 1, r, v[p].rcs);
  push_up(l, r, p);
}
void revise(int l, int r, int p, int nl, int nr) {
  if (nl <= l && r <= nr) return;
  if (nl <= ((l + r) >> 1)) revise(l, ((l + r) >> 1), v[p].lcs, nl, nr);
  if (((l + r) >> 1) + 1 <= nr) revise(((l + r) >> 1) + 1, r, v[p].rcs, nl, nr);
  push_up(l, r, p);
}
}  // namespace T2
struct edges {
  int x, y;
  long long fare;
} edge[100005];
long long last = 0;
int main() {
  int n, q;
  long long w;
  read(n, q, w);
  for (int i = 1; i < n; i++) {
    int x, y;
    long long z;
    read(x, y, z);
    edge[i] = (edges){x, y, z};
    add(x, y, z);
    add(y, x, z);
  }
  T1::dfs1(1);
  T1::dfs2(1, 1);
  for (int now = 1; now <= n; now++)
    for (int i = head[now]; i; i = ne[i])
      if (to[i] != T1::fa[now]) {
        T1::dep.add(T1::id[to[i]], fare[i]);
        T1::dep.add(T1::id[to[i]] + T1::size[to[i]], -fare[i]);
      }
  for (int i = 1; i <= n; i++) T1::idf[T1::id[i]] = i;
  int root = 0;
  T2::build(1, n, root);
  while (q--) {
    int id;
    int u, v;
    long long far;
    read(id, far);
    id = (id + last) % (n - 1) + 1;
    far = (far + last) % w;
    u = edge[id].x;
    v = edge[id].y;
    if (T1::fa[u] == v) swap(u, v);
    T1::dep.add(T1::id[v], far - edge[id].fare);
    T1::dep.add(T1::id[v] + T1::size[v], edge[id].fare - far);
    edge[id].fare = far;
    T2::revise(1, n, 1, T1::id[v], T1::id[v] + T1::size[v] - 1);
    printf("%lld\n", last = T2::v[1].dist);
  }
  return 0;
}
