#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, L = 20;
long long gg[N];
struct SegTree {
  vector<long long> t, up;
  int len;
  void build(int v, int L, int R) {
    if (L == R) {
      t[v] = gg[L];
    } else {
      int m = (L + R) >> 1;
      build(v * 2, L, m);
      build(v * 2 + 1, m + 1, R);
      t[v] = max(t[v * 2], t[v * 2 + 1]);
    }
  }
  void resize(int nlen) {
    len = nlen;
    t.resize(len * 4);
    up.resize(len * 4);
  }
  void push(int v, int L, int R) {
    if (up[v]) {
      if (L != R) {
        up[v * 2] += up[v];
        up[v * 2 + 1] += up[v];
      }
      t[v] += up[v];
      up[v] = 0;
    }
  }
  void upd(int l, int r, long long w, int v, int L, int R) {
    push(v, L, R);
    if (l > r) return;
    if (l == L && r == R) {
      up[v] += w;
      push(v, L, R);
    } else {
      int m = (L + R) >> 1;
      upd(l, min(m, r), w, v * 2, L, m);
      upd(max(m + 1, l), r, w, v * 2 + 1, m + 1, R);
      t[v] = max(t[v * 2], t[v * 2 + 1]);
    }
  }
  long long que(int l, int r, int v, int L, int R) {
    push(v, L, R);
    if (l > r) return 0;
    if (l == L && r == R) {
      return t[v];
    }
    int m = (L + R) >> 1;
    return max(que(l, min(m, r), v * 2, L, m),
               que(max(m + 1, l), r, v * 2 + 1, m + 1, R));
  }
} tr[N];
struct E {
  int a, b;
  long long w;
};
vector<E> g[N];
long long wt[N], cur[N], mx[L][N];
int tin[L][N], tout[L][N], rc[L][N], rt[L][N], sz[N];
bool ban[N];
multiset<long long> st[N], st_ans;
vector<E> edges;
void dfs(int node, int anc) {
  sz[node] = 1;
  for (E e : g[node]) {
    int to = e.a;
    if (to != anc && !ban[to]) {
      dfs(to, node);
      sz[node] += sz[to];
    }
  }
}
int findCen(int node, int anc, int half) {
  for (E e : g[node]) {
    int to = e.a;
    if (!ban[to] && to != anc && sz[to] > half) {
      return findCen(to, node, half);
    }
  }
  return node;
}
int timer = 0;
void deep(int node, int anc, int lvl, int rt_child, int r) {
  rc[lvl][node] = rt_child;
  tin[lvl][node] = ++timer;
  rt[lvl][node] = r;
  for (E e : g[node]) {
    int to = e.a;
    if (to != anc && !ban[to]) {
      deep(to, node, lvl, anc == -1 ? to : rt_child, r);
      gg[tin[lvl][to]] += e.w;
      gg[tout[lvl][to] + 1] -= e.w;
    }
  }
  tout[lvl][node] = timer;
}
void solve(int node, int lvl) {
  dfs(node, -1);
  fill(gg, gg + sz[node], 0);
  node = findCen(node, -1, sz[node] / 2);
  ban[node] = 1;
  timer = -1;
  deep(node, -1, lvl, -1, node);
  tr[node].resize(tout[lvl][node] + 1);
  for (int i = 1; i <= tout[lvl][node]; i++) {
    gg[i] += gg[i - 1];
  }
  tr[node].build(1, 0, tr[node].len - 1);
  for (E e : g[node]) {
    if (!ban[e.a]) {
      mx[lvl][e.a] =
          tr[node].que(tin[lvl][e.a], tout[lvl][e.a], 1, 0, tr[node].len - 1);
      st[node].insert(mx[lvl][e.a]);
    }
  }
  for (E e : g[node]) {
    if (!ban[e.a]) {
      solve(e.a, lvl + 1);
    }
  }
}
long long getAns(int x) {
  if (st[x].empty()) return 0;
  if (st[x].size() == 1) return *st[x].rbegin();
  return *st[x].rbegin() + *next(st[x].rbegin());
}
void ch(int i, long long x) {
  E e = edges[i];
  for (int j = 0; j < L; j++) {
    if (rt[j][e.a] != -1 && rt[j][e.a] == rt[j][e.b]) {
      if (tin[j][e.a] > tin[j][e.b]) swap(e.a, e.b);
      int r = rt[j][e.a];
      tr[r].upd(tin[j][e.b], tout[j][e.b], x - cur[i], 1, 0, tr[r].len - 1);
      int c = rc[j][e.b];
      st_ans.erase(st_ans.find(getAns(r)));
      st[r].erase(st[r].find(mx[j][c]));
      mx[j][c] = tr[r].que(tin[j][c], tout[j][c], 1, 0, tr[r].len - 1);
      st[r].insert(mx[j][c]);
      st_ans.insert(getAns(r));
    }
  }
  cur[i] = x;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(rt, -1, sizeof(rt));
  int n, q;
  long long w;
  cin >> n >> q >> w;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back({b, -1, c});
    g[b].push_back({a, -1, c});
    cur[i] = c;
    edges.push_back({a, b});
  }
  solve(0, 0);
  for (int i = 0; i < n; i++) {
    st_ans.insert(getAns(i));
  }
  long long last = 0;
  for (int i = 0; i < q; i++) {
    long long x, y;
    cin >> x >> y;
    x = (x + last) % (n - 1);
    y = (y + last) % w;
    ch(x, y);
    last = *st_ans.rbegin();
    cout << last << "\n";
  }
  return 0;
}
