#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5,M=20,mod=1e9+7,inf=1e18;
int _t,n,q,w,ans,cnt,m,sb[N],rt[N],id,s[M][4*N],lazy[M][4*N],L[N],R[N],X[N],Y[N],Z[N],d[N],tin[M][N],tout[M][N],pr[M][N];
vector <pair<int,int>> v[N]; pair<int,int> u[M][N]; vector <int> a[N]; multiset <int> st[M][N],as; bool bl[N];
int merge (int a,int b){
return max(a,b);
}
void push(int t,int i,int l,int r){
s[t][i]+=lazy[t][i];
if (l<r){
lazy[t][2*i]+=lazy[t][i];
lazy[t][2*i+1]+=lazy[t][i];
}
lazy[t][i]=0;
}
void upd (int t,int i,int l,int r,int x,int y,int z){
push(t,i,l,r);
if (y<l || x>r) return;
if (x<=l && y>=r){
lazy[t][i]+=z; push(t,i,l,r);
return;
}
upd(t,2*i,l,(l+r)/2,x,y,z);
upd(t,2*i+1,(l+r)/2+1,r,x,y,z);
s[t][i]=merge(s[t][2*i],s[t][2*i+1]);
}
int get (int t,int i,int l,int r,int x,int y){
push(t,i,l,r);
if (y<l || x>r) return 0;
if (x<=l && y>=r) return s[t][i];
return merge(get(t,2*i,l,(l+r)/2,x,y),get(t,2*i+1,(l+r)/2+1,r,x,y));
}
void dfs(int t,int i,int p){
sb[i]=1; tin[t][i]=++cnt;// cout<<t<<" "<<i<<" "<<tin[t][i]<<endl;
for (auto j:v[i]){
if (bl[j.second] || j.first==p) continue;
dfs(t,j.first,i); sb[i]+=sb[j.first];
} tout[t][i]=cnt; //cout<<t<<" "<<i<<" !"<<tout[t][i]<<endl;
}
int cent(int t,int i,int p,int n){
for (auto j:v[i]){
if (bl[j.second] || j.first==p) continue;
if (sb[j.first]>n/2) return cent(t,j.first,i,n);
} return i;
}
void dfs2(int t,int i,int p,int x){
upd(t,1,1,n,tin[t][i],tin[t][i],d[i]);
for (auto j:v[i]){
if (bl[j.second] || j.first==p) continue;
d[j.first]=d[i]+Z[j.second]; u[t][j.second]={j.first,x};
dfs2(t,j.first,i,x);
}
}
void dfs3(int t,int i,int p,int x){
for (auto j:v[i]){
if (bl[j.second] || j.first==p) continue;
pr[t][j.second]=x; dfs3(t,j.first,i,x);
}
}
void solve(){
for (int i=1; i<=n; i++) sb[i]=0; cnt=0;
vector <int> vv;
for (int i=1; i<=n; i++){
if (sb[i]) continue;
dfs(m,i,0); vv.push_back(cent(m,i,0,sb[i]));
} if ((int)vv.size()==n) return; cnt=0;
for (int i:vv){// cout<<m<<" "<<i<<endl;
dfs(m,i,0); d[i]=0; dfs2(m,i,0,i);
for (auto j:v[i]){
if (bl[j.second]) continue; bl[j.second]=1; pr[m][j.second]=j.first;
dfs3(m,j.first,i,j.first);
// cout<<j.first<<" "<<tin[m][j.first]<<" "<<tout[m][j.first]<<endl;
st[m][i].insert(get(m,1,1,n,tin[m][j.first],tout[m][j.first]));
}
auto it=st[m][i].end(); int d=0;
if (it!=st[m][i].begin()) it--,d+=*it;
if (it!=st[m][i].begin()) it--,d+=*it;
as.insert(d);
}
m++; solve();
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>q>>w;
for (int i=1; i<n; i++){
cin>>X[i]>>Y[i]>>Z[i];
v[X[i]].push_back({Y[i],i});
v[Y[i]].push_back({X[i],i});
}
solve();
// for (int i:as) cout<<i<<" "; cout<<endl;
while (q--){
int x,y; cin>>x>>y;
x=(x+ans)%(n-1)+1; y=(y+ans)%w;// cout<<x<<" %"<<y<<endl;
int d=y-Z[x]; Z[x]=y;
for (int i=0; i<m; i++){
if (u[i][x].second==0) continue;
auto it=st[i][u[i][x].second].end(); int e=0;
if (it!=st[i][u[i][x].second].begin()) it--,e+=*it;
if (it!=st[i][u[i][x].second].begin()) it--,e+=*it;
as.erase(as.lower_bound(e));// cout<<u[i][x].second<<"-"<<endl;
// if (x==4 && y==1894) cout<<get(i,1,1,n,tin[i][pr],tout[i][pr])<<" "<<*st[i][u[i][x].second].lower_bound(get(i,1,1,n,tin[i][pr],tout[i][pr]))<<endl;
st[i][u[i][x].second].erase(st[i][u[i][x].second].lower_bound(get(i,1,1,n,tin[i][pr[i][x]],tout[i][pr[i][x]]))); //if (x==4 && y==1894) cout<<i<<endl;
upd(i,1,1,n,tin[i][u[i][x].first],tout[i][u[i][x].first],d);
st[i][u[i][x].second].insert(get(i,1,1,n,tin[i][pr[i][x]],tout[i][pr[i][x]]));
it=st[i][u[i][x].second].end(); e=0;
if (it!=st[i][u[i][x].second].begin()) it--,e+=*it;
if (it!=st[i][u[i][x].second].begin()) it--,e+=*it;
as.insert(e);
// for (int j:st[i][u[i][x].second]) cout<<j<<" "; cout<<endl;
} ans=*(--as.end()); cout<<ans<<"\n";// cout.flush();
}
}