#include <bits/stdc++.h>
using namespace std;
const long long MAXn = 1e5 + 5;
namespace pre {
vector<pair<long long, long long> > v[MAXn];
long long p[MAXn], ed[MAXn];
pair<long long, long long> e[MAXn];
void dfs(long long now, long long f) {
  for (pair<long long, long long> k : v[now])
    if (k.first != f) {
      p[k.first] = now;
      dfs(k.first, now);
    }
}
void go(long long n) {
  for (int i = 1; i <= n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    e[i] = {a, b};
    ed[i] = c;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  p[1] = 0;
  dfs(1, -1);
}
};  // namespace pre
typedef pair<long long *, long long *> tg;
long long zz = 0, *z = &zz;
tg ez = {z, z};
struct node {
  node *p;
  long long mx, d1, d2, len;
  tg omx, nmx, nlen;
  pair<tg, tg> nd1, nd2;
  node()
      : p(0),
        mx(0),
        d1(0),
        d2(0),
        len(0),
        omx(ez),
        nmx(ez),
        nlen(ez),
        nd1({ez, ez}),
        nd2({ez, ez}) {}
  void setv(long long x) { mx = d1 = d2 = len = x; }
  void pull() {
    mx = max({*omx.first, *omx.second, *nmx.first + *nmx.second});
    len = *nlen.first + *nlen.second;
    d1 = max(*nd1.first.first + *nd1.first.second,
             *nd1.second.first + *nd1.second.second);
    d2 = max(*nd2.first.first + *nd2.first.second,
             *nd2.second.first + *nd2.second.second);
  }
};
vector<long long> v[MAXn];
long long ed[MAXn], u[MAXn], nct, e[MAXn];
node *en[MAXn], *nd[MAXn];
void dfs(long long now) {
  u[now] = 0;
  for (long long k : v[now]) dfs(k);
  if (!((int)(v[now]).size())) return;
  if (((int)(v[now]).size()) == 1 && !u[v[now][0]] && now != 1) {
    long long a = now, b = v[now][0];
    u[a] = u[b] = 1;
    node *n = new node(), *na = nd[a], *nb = nd[b];
    na->p = nb->p = n;
    n->omx = {&na->mx, &nb->mx};
    n->nmx = {&na->d2, &nb->d1};
    n->nlen = {&na->len, &nb->len};
    n->nd1 = {{&na->d1, z}, {&nb->d1, &na->len}};
    n->nd2 = {{&nb->d2, z}, {&na->d2, &nb->len}};
    v[a] = v[b];
    nd[a] = n;
    n->pull();
    nct--;
    return;
  }
  vector<long long> nv;
  vector<pair<long long, long long> > pv;
  queue<long long> qa, qb;
  for (long long x : v[now])
    if (!u[x]) {
      if (((int)(v[x]).size()) == 0)
        qa.push(x);
      else
        qb.push(x);
    } else
      nv.push_back(x);
  while (((int)(qa).size())) {
    long long a = qa.front(), b;
    qa.pop();
    if (((int)(qb).size()))
      b = qb.front(), qb.pop();
    else if (((int)(qa).size()))
      b = qa.front(), qa.pop();
    else {
      nv.push_back(a);
      break;
    }
    pv.push_back({a, b});
  }
  while (((int)(qb).size())) nv.push_back(qb.front()), qb.pop();
  for (auto &p : pv) {
    long long a = p.first, b = p.second;
    u[a] = u[b] = 1;
    node *n = new node(), *na = nd[a], *nb = nd[b];
    na->p = nb->p = n;
    n->omx = {&na->mx, &nb->mx};
    n->nmx = {&na->d1, &nb->d1};
    n->nlen = {&nb->len, z};
    n->nd1 = {{&na->d1, z}, {&nb->d1, z}};
    n->nd2 = {{&nb->d2, z}, {&na->d1, &nb->len}};
    nv.push_back(b);
    nd[b] = n;
    n->pull();
    nct--;
  }
  v[now] = nv;
}
void upd(node *n) {
  while (n->p) {
    n = n->p, n->pull();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, q, w;
  cin >> n >> q >> w;
  pre::go(n);
  for (int i = 1; i <= n - 1; i++)
    e[i] = (pre::p[pre::e[i].first] == pre::e[i].second ? pre::e[i].first
                                                        : pre::e[i].second);
  for (int i = 2; i <= n; i++) v[pre::p[i]].push_back(i);
  for (int i = 1; i <= n - 1; i++) {
    ed[i] = pre::ed[i];
    en[i] = new node();
    en[i]->setv(ed[i]);
    nd[e[i]] = en[i];
  }
  nct = n - 1;
  while (nct > 1) dfs(1);
  node *rt = nd[v[1][0]];
  long long lst = 0;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    a = (a + lst) % (n - 1) + 1;
    b = (b + lst) % w;
    en[a]->setv(b);
    upd(en[a]);
    long long ans = rt->mx;
    cout << ans << '\n';
    lst = ans;
  }
}
