#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
long long read() {
  long long x = 0, pos = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') pos = 0;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return pos ? x : -x;
}
const long long N = 1e5 + 200;
struct node {
  long long v, nex, typ;
  long long w;
} edge[N * 2];
long long head[N], tope = 0;
inline void add(long long u, long long v, long long w, long long typ) {
  edge[++tope].v = v;
  edge[tope].nex = head[u];
  edge[tope].w = w;
  edge[tope].typ = typ;
  head[u] = tope;
}
long long dep[N];
long long dw[N];
long long n, q, top[N], lnk[N], ed[N], sz[N], son[N], fa[N], cnt, knl[N], bl[N],
    aw[N];
long long w;
inline void dfs(long long now, long long pre) {
  dep[now] = dep[pre] + 1;
  sz[now] = 1;
  fa[now] = pre;
  for (long long i = head[now]; i; i = edge[i].nex) {
    long long v = edge[i].v;
    if (v == pre) continue;
    bl[edge[i].typ] = v;
    dw[v] = dw[now] + edge[i].w;
    dfs(v, now);
    if (sz[v] > sz[son[now]]) son[now] = v;
    sz[now] += sz[v];
  }
}
inline void dfs2(long long now, long long tp) {
  top[now] = tp;
  lnk[now] = ++cnt;
  knl[cnt] = now;
  if (son[now]) dfs2(son[now], tp);
  for (long long i = head[now]; i; i = edge[i].nex) {
    long long v = edge[i].v;
    if (v == fa[now] || v == son[now]) continue;
    dfs2(v, v);
  }
  ed[now] = cnt;
}
long long c[N];
inline void addt(long long x, long long w) {
  for (; x <= n; x += (x & (-x))) c[x] += w;
}
inline long long query(long long x) {
  long long res = 0;
  for (; x; x -= (x & (-x))) res += c[x];
  return res;
}
inline long long dis(long long a, long long b) {
  long long res = dw[a] + dw[b] + query(lnk[a]) + query(lnk[b]);
  while (top[a] != top[b]) {
    if (dep[top[a]] < dep[top[b]]) swap(a, b);
    a = fa[top[a]];
  }
  if (dep[a] > dep[b]) swap(a, b);
  return res - 2ll * dw[a] - 2ll * query(lnk[a]);
}
long long d[N * 4], p1[N * 4], p2[N * 4];
inline void push_up(long long now) {
  if (d[now << 1] > d[now << 1 | 1]) {
    d[now] = d[now << 1], p1[now] = p1[now << 1], p2[now] = p2[now << 1];
  } else
    d[now] = d[now << 1 | 1], p1[now] = p1[now << 1 | 1],
    p2[now] = p2[now << 1 | 1];
  long long x1 = p1[now << 1], x2 = p2[now << 1], x3 = p1[now << 1 | 1],
            x4 = p2[now << 1 | 1];
  long long dn = dis(x1, x3);
  if (d[now] < dn) {
    d[now] = dn, p1[now] = x1, p2[now] = x3;
  }
  dn = dis(x1, x4);
  if (d[now] < dn) {
    d[now] = dn, p1[now] = x1, p2[now] = x4;
  }
  dn = dis(x2, x3);
  if (d[now] < dn) {
    d[now] = dn, p1[now] = x2, p2[now] = x3;
  }
  dn = dis(x2, x4);
  if (d[now] < dn) {
    d[now] = dn, p1[now] = x2, p2[now] = x4;
  }
}
inline void build(long long now, long long l, long long r) {
  if (l == r) {
    p1[now] = p2[now] = knl[l];
    return;
  }
  long long mid = (l + r) >> 1;
  build(now << 1, l, mid);
  build(now << 1 | 1, mid + 1, r);
  push_up(now);
}
inline void modify(long long now, long long l, long long r, long long ql,
                   long long qr) {
  if (ql <= l && r <= qr) return;
  long long mid = (l + r) >> 1;
  if (ql <= mid) modify(now << 1, l, mid, ql, qr);
  if (mid < qr) modify(now << 1 | 1, mid + 1, r, ql, qr);
  if ((r >= ql && l <= ql) || (l <= qr && qr <= r)) push_up(now);
}
int main() {
  n = read(), q = read();
  w = read();
  for (register long long i = 1; i <= n - 1; ++i) {
    long long a = read(), b = read(), c = read();
    aw[i] = c;
    add(a, b, c, i);
    add(b, a, c, i);
  }
  dfs(1, 0);
  dfs2(1, 1);
  long long las = 0;
  build(1, 1, n);
  for (register long long i = 1; i <= q; ++i) {
    long long dn = (las + read()) % (n - 1) + 1;
    long long en = (las + read()) % w;
    en -= aw[dn];
    aw[dn] += en;
    dn = bl[dn];
    addt(lnk[dn], en);
    addt(ed[dn] + 1, -en);
    modify(1, 1, n, lnk[dn], ed[dn]);
    las = d[1];
    printf("%lld\n", las);
  }
  return 0;
}
