#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long inf = 1ll << 60;
struct seg {
  int l, r, mid;
  long long ans = 0, lz = 0;
  seg *ch[2]{};
  void push() {
    for (auto &i : ch) i->ans += lz, i->lz += lz;
    lz = 0;
  }
  void add(int _l, int _r, long long val) {
    if (_l > _r) return;
    if (_l <= l and _r >= r) {
      ans += val;
      lz += val;
      return;
    }
    if (_l > r or _r < l) return;
    push();
    for (auto &i : ch) i->add(_l, _r, val);
    ans = max(ch[0]->ans, ch[1]->ans);
  }
  void set(int pos, long long val) {
    if (l == r) {
      ans = val;
      return;
    }
    push();
    if (pos <= mid)
      ch[0]->set(pos, val);
    else
      ch[1]->set(pos, val);
    ans = max(ch[0]->ans, ch[1]->ans);
  }
  long long query(int _l, int _r) {
    if (_l > _r) return 0;
    if (_l <= l and _r >= r) return ans;
    if (_l > r or _r < l) return -inf;
    push();
    return max(ch[0]->query(_l, _r), ch[1]->query(_l, _r));
  }
  int mapos() {
    if (l == r) return l;
    push();
    if (ch[0]->ans > ch[1]->ans)
      return ch[0]->mapos();
    else
      return ch[1]->mapos();
  }
  seg(int _l, int _r) : l(_l), r(_r), mid(l + r >> 1) {
    if (l != r) ch[0] = new seg(l, mid), ch[1] = new seg(mid + 1, r);
  }
} *rt = new seg(0, N - 1), *rt2 = new seg(0, N - 1);
int sz[N]{}, st[N], ed[N], par[N], hd[N], go[N]{}, pos[N], t = 0;
vector<int> g[N];
void dfs(int u, int p) {
  sz[u] = 1;
  par[u] = p;
  for (int i : g[u])
    if (i != p) {
      dfs(i, u);
      sz[u] += sz[i];
      if (sz[i] > sz[go[u]]) go[u] = i;
    }
}
void hld(int u, int p, int h) {
  hd[u] = h;
  st[u] = t++;
  pos[st[u]] = u;
  if (go[u]) hld(go[u], u, h);
  for (int i : g[u])
    if (i != go[u] and i != p) hld(i, u, i);
  ed[u] = t - 1;
}
map<pair<int, int>, long long> cur;
void modify(int u, int p, long long w) {
  if (par[u] != p) swap(u, p);
  rt->add(st[u], ed[u], w - cur[{u, p}]);
  rt2->add(st[u], ed[u], cur[{u, p}] - w);
  cur[{u, p}] = cur[{p, u}] = w;
  while (true) {
    u = par[hd[u]];
    if (!u) break;
    rt2->set(st[u],
             rt->query(ed[go[u]] + 1, ed[u]) - 2 * rt->query(st[u], st[u]));
  }
}
long long query(int u) {
  long long ans = 0;
  while (true) {
    int tmp = hd[u];
    if (par[u]) ans = max(ans, rt2->query(st[tmp], st[par[u]]));
    u = par[hd[u]];
    if (!u) break;
    long long _ans =
        max(rt->query(st[u], st[tmp] - 1), rt->query(ed[tmp] + 1, ed[u])) -
        2 * rt->query(st[u], st[u]);
    ans = max(ans, _ans);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, q;
  long long W, w;
  cin >> n >> q >> W;
  vector<pair<pair<int, int>, long long>> init;
  for (int i = 0, a, b; i < n - 1; i++) {
    cin >> a >> b >> w;
    init.push_back({{a, b}, w});
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  hld(1, 0, 1);
  for (auto i : init) modify(i.first.first, i.first.second, i.second);
  long long last = 0;
  for (int i = 0, a; i < q; i++) {
    cin >> a >> w;
    a = (a + last) % (n - 1);
    w = (w + last) % W;
    modify(init[a].first.first, init[a].first.second, w);
    int u = pos[rt->mapos()];
    last = query(u) + rt->query(st[u], st[u]);
    cout << last << '\n';
  }
}
