#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long INF = 1ull << 63 - 1;
int n, m;
long long W;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) (ch == '-') && (f = -f), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int head[MAXN], trump = 1;
int to[MAXN];
struct Edge {
  int to, next;
  long long val;
  Edge(int u = 0, int v = 0, long long w = 0) : to(v), next(head[u]), val(w){};
} e[MAXN << 1];
inline void addedge(int u, int v, long long w) {
  e[++trump] = Edge(u, v, w);
  head[u] = trump;
  e[++trump] = Edge(v, u, w);
  head[v] = trump;
}
int tour[MAXN << 1], st[MAXN], ed[MAXN], dfn;
long long dis[MAXN];
void dfs(int u, int fa) {
  tour[st[u] = ++dfn] = u;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    dis[v] = dis[u] + e[i].val;
    to[i >> 1] = v;
    dfs(v, u);
    tour[++dfn] = u;
  }
  tour[ed[u] = ++dfn] = u;
}
struct Node {
  int l, r;
  long long tag;
  long long minn, maxn;
  long long LM, MR, LMR;
} t[MAXN << 3];
inline void pushup(int k) {
  t[k].minn = min(t[(k << 1)].minn, t[(k << 1 | 1)].minn);
  t[k].maxn = max(t[(k << 1)].maxn, t[(k << 1 | 1)].maxn);
  t[k].LM = max(max(t[(k << 1)].LM, t[(k << 1 | 1)].LM),
                t[(k << 1)].maxn - 2 * t[(k << 1 | 1)].minn);
  t[k].MR = max(max(t[(k << 1)].MR, t[(k << 1 | 1)].MR),
                t[(k << 1 | 1)].maxn - 2 * t[(k << 1)].minn);
  t[k].LMR = max(max(t[(k << 1)].LMR, t[(k << 1 | 1)].LMR),
                 max(t[(k << 1)].LM + t[(k << 1 | 1)].maxn,
                     t[(k << 1)].maxn + t[(k << 1 | 1)].MR));
}
inline void addtag(int k, long long v) {
  t[k].minn += v;
  t[k].maxn += v;
  t[k].LM -= v;
  t[k].MR -= v;
  t[k].tag += v;
}
inline void pushdown(int k) {
  addtag((k << 1), t[k].tag);
  addtag((k << 1 | 1), t[k].tag);
  t[k].tag = 0;
}
void build(int k, int l, int r) {
  t[k].l = l;
  t[k].r = r;
  if (l == r)
    return t[k].minn = t[k].maxn = dis[tour[l]],
           t[k].LM = t[k].MR = t[k].LMR = -W * W, void();
  int mid = (l + r) >> 1;
  build((k << 1), l, mid);
  build((k << 1 | 1), mid + 1, r);
  pushup(k);
}
void modify(int k, int l, int r, long long v) {
  if (t[k].l >= l && t[k].r <= r) return addtag(k, v);
  if (t[k].l > r || t[k].r < l) return;
  pushdown(k);
  modify((k << 1), l, r, v);
  modify((k << 1 | 1), l, r, v);
  pushup(k);
}
int main() {
  int i;
  long long last = 0;
  n = read();
  m = read();
  W = read();
  for (i = 1; i < n; ++i) {
    int u = read(), v = read();
    long long w = read();
    addedge(u, v, w);
  }
  dfs(1, 0);
  build(1, 1, dfn);
  for (i = 1; i <= m; ++i) {
    int d = (read() + last) % (n - 1) + 1;
    long long w = (read() + last) % W - e[d << 1].val;
    e[d << 1].val += w;
    e[d << 1 | 1].val += w;
    modify(1, st[to[d]], ed[to[d]], w);
    printf("%lld\n", last = t[1].LMR);
  }
  return 0;
}
