#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
template <typename X>
struct seg_lazy {
  X t[N << 1];
  long long lz[N << 1];
  void merge(pair<long long, long long> &a, long long b) { a.first += b; }
  void merge(long long &a, long long b) { a += b; }
  void push(int p = 1, int l = 1, int r = N) {
    if (!lz[p]) return;
    merge(t[p], lz[p]);
    if (l != r) lz[p << 1] += lz[p], lz[p << 1 | 1] += lz[p];
    lz[p] = 0;
  }
  template <typename T>
  void travel(int first, int second, const T &f, int p = 1, int l = 1,
              int r = N) {
    push(p, l, r);
    if (first > r || l > second) return;
    if (first <= l && r <= second) return f(p, l, r);
    travel(first, second, f, p << 1, l, (l + r >> 1)),
        travel(first, second, f, p << 1 | 1, (l + r >> 1) + 1, r);
    t[p] = max(t[p << 1], t[p << 1 | 1]);
  }
};
seg_lazy<pair<long long, long long> > lazy;
seg_lazy<long long> tmx;
int n, q;
long long w;
vector<pair<long long, long long> > g[N];
set<pair<long long, long long> > S1[N], S2[N];
int in[N], out[N], par[N], dep[N], pos[N], mxp[N], spi[N], rot[N];
long long d[N], dp[N];
int dfs(int u, int p) {
  static int idx = 0;
  in[u] = ++idx;
  par[u] = p, dep[u] = dep[p] + 1;
  int sz = 1;
  pair<long long, long long> ret(0, -1);
  for (pair<long long, long long> v : g[u])
    if (v.first != p) {
      d[v.first] = d[u] + v.second;
      int z = dfs(v.first, u);
      dp[u] = max(dp[u], dp[v.first] + v.second);
      sz += z, ret = max(ret, pair<long long, long long>(z, v.first));
    }
  spi[u] = ret.second, out[u] = idx;
  return sz;
}
void hld_upd(int u) {
  while (u) {
    int nex = par[rot[u]];
    long long dp, now = 0;
    lazy.travel(in[nex], in[nex],
                [&](int p = 1, int l = 1, int r = N) { dp = lazy.t[p].first; });
    lazy.travel(in[rot[u]], out[rot[u]], [&](int p = 1, int l = 1, int r = N) {
      now = max(now, lazy.t[p].first);
    });
    pair<long long, long long> p =
        *S2[nex].lower_bound(pair<long long, long long>(rot[u], -1e18));
    S2[nex].erase(p),
        S2[nex].emplace(pair<long long, long long>(rot[u], now - dp));
    S1[nex].erase(pair<long long, long long>(p.second, p.first)),
        S1[nex].emplace(pair<long long, long long>(now - dp, rot[u]));
    tmx.travel(pos[nex], pos[nex], [&](int p = 1, int l = 1, int r = N) {
      tmx.t[p] = S1[nex].rbegin()->first - dp;
    });
    u = nex;
  }
}
long long hld_que(int u) {
  long long dp, ret = -1e18;
  lazy.travel(in[u], in[u],
              [&](int p = 1, int l = 1, int r = N) { dp = lazy.t[p].first; });
  lazy.travel(in[u], out[u], [&](int p = 1, int l = 1, int r = N) {
    ret = max(ret, lazy.t[p].first - 2ll * dp);
  });
  while (u) {
    long long tdp, now = -1e8;
    lazy.travel(
        in[par[rot[u]]], in[par[rot[u]]],
        [&](int p = 1, int l = 1, int r = N) { tdp = lazy.t[p].first; });
    lazy.travel(in[par[rot[u]]], in[rot[u]] - 1,
                [&](int p = 1, int l = 1, int r = N) {
                  now = max(now, lazy.t[p].first - 2ll * tdp);
                });
    lazy.travel(out[rot[u]] + 1, out[par[rot[u]]],
                [&](int p = 1, int l = 1, int r = N) {
                  now = max(now, lazy.t[p].first - 2ll * tdp);
                });
    tmx.travel(pos[rot[u]], pos[u] - 1, [&](int p = 1, int l = 1, int r = N) {
      now = max(now, tmx.t[p]);
    });
    ret = max(ret, now);
    u = par[rot[u]];
  }
  return ret;
}
void gen_tree() {
  function<int(int, int, int)> get = [&](int u, int p, int r) {
    static int idx = 0;
    pos[u] = mxp[u] = ++idx, rot[u] = r;
    for (pair<long long, long long> v : g[u])
      if (v.first != p && v.first != spi[u]) {
        S1[u].emplace(dp[v.first], v.first);
        S2[u].emplace(v.first, dp[v.first]);
      }
    if (spi[u] != -1) mxp[u] = max(mxp[u], get(spi[u], u, r));
    for (pair<long long, long long> v : g[u])
      if (v.first != p && v.first != spi[u])
        mxp[u] = max(mxp[u], get(v.first, u, v.first));
    return mxp[u];
  };
  get(1, 0, 1);
  for (int i = 1; i <= n; i++)
    lazy.travel(in[i], in[i], [&](int p = 1, int l = 1, int r = N) {
      lazy.t[p] = pair<long long, long long>(d[i], i);
    });
  for (int i = 1; i <= n; i++)
    tmx.travel(pos[i], pos[i],
               [&](int p = 1, int l = 1, int r = N) { tmx.t[p] = -d[i]; });
  for (int i = 1; i <= n; i++) hld_upd(i);
}
long long get_diameter() {
  pair<long long, long long> a(0, 0);
  lazy.travel(1, n,
              [&](int p = 1, int l = 1, int r = N) { a = max(a, lazy.t[p]); });
  return hld_que(a.second) + a.first;
}
vector<pair<long long, long long> > E;
long long cost[N];
int main() {
  scanf("%d %d %lld", &n, &q, &w);
  for (int i = 1; i < n; i++) {
    int a, b;
    long long c;
    scanf("%d %d %lld", &a, &b, &c);
    g[a].emplace_back(b, c), g[b].emplace_back(a, c);
    E.emplace_back(a, b), cost[i - 1] = c;
  }
  dfs(1, 0), gen_tree();
  for (pair<long long, long long> &e : E)
    if (dep[e.first] < dep[e.second]) swap(e.first, e.second);
  long long last = 0;
  for (int i = 1; i <= q; i++) {
    int d;
    long long e;
    scanf("%d %lld", &d, &e);
    d = (d + last) % (n - 1);
    e = (e + last) % w;
    int u = E[d].first;
    lazy.travel(in[u], out[u], [&](int p = 1, int l = 1, int r = N) {
      lazy.lz[p] += e - cost[d];
      lazy.push(p, l, r);
    });
    tmx.travel(pos[u], mxp[u], [&](int p = 1, int l = 1, int r = N) {
      tmx.lz[p] -= e - cost[d];
      tmx.push(p, l, r);
    });
    hld_upd(u);
    cost[d] = e;
    last = get_diameter();
    printf("%lld\n", last);
  }
  return 0;
}
