#include <bits/stdc++.h>
using namespace std;
struct io_t {
  static const int MAXI = 1 << 14;
  char I[MAXI];
  int ii = MAXI;
  static const int MAXO = 1 << 14;
  char O[MAXO];
  int oi = 0;
  ~io_t() { flush(); }
  void flush() {
    fwrite(O, 1, oi, stdout);
    oi = 0;
  }
  char nextChar() {
    if (ii == MAXI) {
      ii = 0;
      int p = fread(I, 1, MAXI, stdin);
      fill(I + p, I + MAXI, EOF);
    }
    return I[ii++];
  }
  void printChar(char c) {
    if (oi == MAXO) {
      flush();
    }
    O[oi++] = c;
  }
  template <typename T>
  io_t& operator>>(T& res) {
    char c;
    while ((c = nextChar()) < '0')
      ;
    res = c - '0';
    while ((c = nextChar()) >= '0') res = 10 * res + c - '0';
    return *this;
  }
  io_t& operator<<(int n) {
    static char buf[20];
    int sz = 0;
    do {
      buf[sz++] = n % 10 + '0';
      n /= 10;
    } while (n);
    while (sz--) printChar(buf[sz]);
    return *this;
  }
  io_t& operator<<(long long n) {
    static char buf[20];
    int sz = 0;
    do {
      buf[sz++] = n % 10 + '0';
      n /= 10;
    } while (n);
    while (sz--) printChar(buf[sz]);
    return *this;
  }
  io_t& operator<<(char c) {
    printChar(c);
    return *this;
  }
} io;
using ll = long long;
struct seg {
  ll sum = 0;
  ll bestD = 0;
  ll bestM = 0;
  ll bestD1M = 0;
  ll bestMD2 = 0;
  ll bestD1MD2 = 0;
  void set(ll d) {
    sum = d;
    bestD = d;
    bestM = -2 * d;
    bestD1M = -d;
    bestMD2 = -d;
    bestD1MD2 = 0;
  }
  void shift(ll d) {
    sum += d;
    bestD += d;
    bestM += -2 * d;
    bestD1M += -1 * d;
    bestMD2 += -1 * d;
    bestD1MD2 += 0 * d;
  }
  seg() {}
  seg(const seg& a, const seg& b_) {
    seg b = b_;
    b.shift(a.sum);
    sum = b.sum;
    bestD = max(a.bestD, b.bestD);
    bestM = max(a.bestM, b.bestM);
    bestD1M = max({a.bestD1M, b.bestD1M, a.bestD + b.bestM});
    bestMD2 = max({a.bestMD2, b.bestMD2, a.bestM + b.bestD});
    bestD1MD2 = max(
        {a.bestD1MD2, b.bestD1MD2, a.bestD + b.bestMD2, a.bestD1M + b.bestD});
  }
};
const int MAXN = 1.1e5;
int N, Q;
ll W;
struct edge_t {
  int c[2];
  ll w;
  int other(int a) { return c[0] ^ c[1] ^ a; }
};
edge_t E[MAXN];
vector<int> adj[MAXN];
int st[MAXN], en[MAXN];
void dfs(int cur, int prv, int& ind) {
  for (int e : adj[cur]) {
    int nxt = E[e].other(cur);
    if (nxt == prv) continue;
    st[e] = ind++;
    dfs(nxt, cur, ind);
    en[e] = ind++;
  }
}
const int MAXS = 1 << 19;
int S;
seg nodes[MAXS];
void update(int a, ll w) {
  a += S;
  nodes[a].set(w);
  for (a /= 2; a >= 1; a /= 2) {
    nodes[a] = seg(nodes[2 * a], nodes[2 * a + 1]);
  }
}
int main() {
  io >> N >> Q >> W;
  for (int e = 0; e < N - 1; e++) {
    io >> E[e].c[0] >> E[e].c[1] >> E[e].w;
    adj[E[e].c[0]].push_back(e);
    adj[E[e].c[1]].push_back(e);
  }
  int ind = 0;
  dfs(1, 0, ind);
  for (S = 1; S < 2 * (N - 1); S *= 2)
    ;
  for (int e = 0; e < N - 1; e++) {
    nodes[st[e] + S].set(E[e].w);
    nodes[en[e] + S].set(-E[e].w);
  }
  for (int i = S - 1; i >= 1; i--) {
    nodes[i] = seg(nodes[2 * i], nodes[2 * i + 1]);
  }
  ll last = 0;
  for (int q = 0; q < Q; q++) {
    int e;
    ll w;
    io >> e >> w;
    e = (e + last) % (N - 1);
    w = (w + last) % W;
    update(st[e], w);
    update(en[e], -w);
    ll ans = nodes[1].bestD1MD2;
    io << ans << '\n';
    last = ans;
  }
  return 0;
}
