#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
const long long inf = -2e18;
struct data {
  int to, next, v;
} e[N];
int head[N], cnt, type[N], n, m, L[N], R[N], i, ind, x, y;
long long s[N], w[N], j, mod, ans;
struct node {
  long long a, b, lm, rm, lp, rp, dis;
} t[N << 2];
void ins(int u, int v, long long w) {
  e[++cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt;
  e[cnt].v = w;
}
void insert(int u, int v, long long w) {
  ins(u, v, w);
  ins(v, u, w);
}
void pushup(int rt, int l) {
  t[rt].a = t[rt].b = 0;
  t[rt].lm = t[rt].rm = t[rt].lp = t[rt].rp = t[rt].dis = inf;
  if (type[l] == -1)
    t[rt].b = s[l];
  else if (type[l] == -2)
    t[rt].a = s[l];
  else
    t[rt].lm = t[rt].rm = t[rt].lp = t[rt].rp = 0;
}
void update(int rt) {
  t[rt].a = t[(rt << 1)].a + max(t[(rt << 1 | 1)].a - t[(rt << 1)].b, 0ll);
  t[rt].b = t[(rt << 1 | 1)].b + max(t[(rt << 1)].b - t[(rt << 1 | 1)].a, 0ll);
  t[rt].rp =
      max(t[(rt << 1 | 1)].rp,
          max(t[(rt << 1)].rp - t[(rt << 1 | 1)].a + t[(rt << 1 | 1)].b,
              t[(rt << 1)].rm + t[(rt << 1 | 1)].a + t[(rt << 1 | 1)].b));
  t[rt].rm = max(t[(rt << 1 | 1)].rm,
                 t[(rt << 1)].rm + t[(rt << 1 | 1)].a - t[(rt << 1 | 1)].b);
  t[rt].lp = max(t[(rt << 1)].lp,
                 max(t[(rt << 1 | 1)].lp - t[(rt << 1)].b + t[(rt << 1)].a,
                     t[(rt << 1 | 1)].lm + t[(rt << 1)].a + t[(rt << 1)].b));
  t[rt].lm = max(t[(rt << 1)].lm,
                 t[(rt << 1 | 1)].lm + t[(rt << 1)].b - t[(rt << 1)].a);
  t[rt].dis = max(max(t[(rt << 1)].dis, t[(rt << 1 | 1)].dis),
                  max(t[(rt << 1)].rp + t[(rt << 1 | 1)].lm,
                      t[(rt << 1)].rm + t[(rt << 1 | 1)].lp));
}
void build(int rt, int l, int r) {
  if (l == r) {
    pushup(rt, l);
    return;
  }
  int mid = l + r >> 1;
  build((rt << 1), l, mid);
  build((rt << 1 | 1), mid + 1, r);
  update(rt);
}
void modify(int rt, int l, int r, int pos) {
  if (l == r) {
    pushup(rt, l);
    return;
  }
  int mid = l + r >> 1;
  pos <= mid ? modify((rt << 1), l, mid, pos)
             : modify((rt << 1 | 1), mid + 1, r, pos);
  update(rt);
}
void dfs(int x, int id) {
  s[++ind] = w[id];
  L[id] = ind;
  type[ind] = -1;
  s[++ind] = x;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].v != id) dfs(e[i].to, e[i].v);
  s[++ind] = w[id];
  type[ind] = -2;
  R[id] = ind;
}
int main() {
  for (scanf("%d%d%lld", &n, &m, &mod), i = 1; i < n; ++i)
    scanf("%d%d%lld", &x, &y, w + i), insert(x, y, i);
  dfs(1, 0);
  build(1, 1, ind);
  for (; m--;) {
    scanf("%d%lld", &i, &j);
    i = (i + ans) % (n - 1) + 1;
    j = (j + ans) % mod;
    s[L[i]] = j;
    s[R[i]] = j;
    modify(1, 1, ind, L[i]);
    modify(1, 1, ind, R[i]);
    printf("%lld\n", ans = t[1].dis);
  }
}
