// Original C++ solution (slower):
#include <stdio.h>

#include <iostream>

#include <vector>

using namespace std;

typedef long long ll;

 

vector<pair<int, ll> > path[100005];

int par[100005];

int dep[100005];

int siz[100005];

ll cst[100005];

int hev[100005];

void dfs(int a){

	siz[a]=1;

	for(int i=0; i<path[a].size(); i++){

		int d=path[a][i].first;

		if(d==par[a]) continue;

		par[d]=a;

		dep[d]=dep[a]+1;

		cst[d]=path[a][i].second;

		dfs(d);

		siz[a]+=siz[d];

		if(!hev[a] || siz[hev[a]]<siz[d])

			hev[a]=d;

	}

}

 

ll k;

ll add[100005];

ll edgecost(int a){

	ll ret=add[a]+add[par[a]]+cst[a];

	return ret%k?ret:0;

}

 

int pos[100005];

int hl_par[100005];

 

ll bit[100005];

ll sum(int i){

	ll ret=0;

	while(i){

		ret+=bit[i];

		i-=i&-i;

	}

	return ret;

}

void set(int i, ll x){

	// printf("set %d %lld\n", i, x);

	x-=sum(i+1)-sum(i);

	i++;

	while(i<100005){

		bit[i]+=x;

		i+=i&-i;

	}

}

 

int lca(int a, int b){

	int p=hl_par[a], q=hl_par[b];

	if(p==q) return dep[a]<dep[b]?a:b;

	if(dep[p]<dep[q]) return lca(a, par[q]);

	else return lca(par[p], b);

}

ll cost(int a){

	ll ret=0;

	while(a){

		int p=hl_par[a];

		ret+=sum(pos[a])-sum(pos[p]);

		if(p) ret+=edgecost(p);

		// printf("%d->%d:%lld %d->%d:%lld\n", a, p, sum(pos[a])-sum(pos[p]), p, par[p], edgecost(p));

		a=par[p];

	}

	return ret;

}

 

int main(){

	int n;

	cin >> n >> k;

	for(int i=0; i<n-1; i++){

		int a, b;

		ll c;

		cin >> a >> b >> c;

		path[a].push_back(make_pair(b, c));

		path[b].push_back(make_pair(a, c));

	}

	for(int i=0; i<n; i++) hev[i]=0;

	par[0]=dep[0]=cst[0]=0;

	dfs(0);

 

	for(int i=0; i<n; i++) add[i]=0;

 

	int cnt=0;

	for(int i=0; i<n; i++) pos[i]=-1;

	for(int i=0; i<n; i++){

		if(i && hev[par[i]]==i) continue;

		int j=i;

		do{

			// printf("%d ", j);

			pos[j]=cnt++;

			hl_par[j]=i;

		}while(j=hev[j]);

	}

	// printf("\n");



	for(int i=0; i<100005; i++) bit[i]=0;

	for(int i=0; i<n; i++)

		set(pos[i], edgecost(hev[i]));

	 

	int q;

	cin >> q;

	for(int i=0; i<q; i++){

		string s;

		ll a, b;

		cin >> s >> a >> b;

		if(s[0]=='a'){

			add[a]+=b;

			// for(int i=0; i<10; i++) printf("%lld ", sum(i)); printf("\n");

			set(pos[a], edgecost(hev[a]));

			if(a) set(pos[a]-1, edgecost(a));

			// for(int i=0; i<10; i++) printf("%lld ", sum(i)); printf("\n");

		}else{

			cout << (cost(a)+cost(b)-2*cost(lca(a, b))) << endl;

		}

	}

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cmath>

#include <vector>

using namespace std;

typedef long long ll;

 

ll k;

ll MOD(int a){

	if(a%k==0) return 0;

	else return a;

}

  

vector<pair<int, ll> > path[100005];

int par[100005];

int dep[100005];

ll cst[100005];

void dfs(int a){

	for(int i=0; i<path[a].size(); i++){

		int d=path[a][i].first;

		if(d==par[a]) continue;

		par[d]=a;

		dep[d]=dep[a]+1;

		cst[d]=path[a][i].second;

		dfs(d);

	}

}

ll add[100005];

  

struct query{

	char t;

	ll a, b;

};

query qry[100005];

  

bool used[100005];

int cnt[100005];

int cntdfs(int a){

	cnt[a]=used[a];

	for(int i=0; i<path[a].size(); i++){

		int d=path[a][i].first;

		if(d!=par[a]) cnt[a]+=cntdfs(d);

	}

	return cnt[a];

}

int ming_par[100005];

ll ming_cst[100005];

int ming_bef[100005];

  

int main(){

	int n;

	cin >> n >> k;

	for(int i=0; i<n-1; i++){

		int a, b;

		ll c;

		cin >> a >> b >> c;

		path[a].push_back(make_pair(b, c));

		path[b].push_back(make_pair(a, c));

	}

	par[0]=dep[0]=cst[0]=0;

	dfs(0);

  

	int q;

	cin >> q;

	for(int i=0; i<q; i++){

		string str;

		ll a, b;

		cin >> str >> a >> b;

		qry[i]={str[0], a, b};

	}

  

	for(int i=0; i<n; i++) add[i]=0;

	  

	int sq=(int)(sqrt(q));

	for(int i=0; i<sq; i++){

		int s=i*sq, t=(i+1)*sq;

		if(i==sq-1) t=q;

		  

		used[0]=true;

		for(int j=1; j<n; j++) used[j]=false;

		for(int j=s; j<t; j++){

			if(qry[j].t=='a') 

				used[qry[j].a]=true;

			else

				used[qry[j].a]=used[qry[j].b]=true;

		}

		cntdfs(0);

		for(int j=1; j<n; j++) 

			if(0<cnt[j] && cnt[j]<cnt[par[j]])

				used[par[j]]=true;

  

		for(int j=1; j<n; j++){

			if(!used[j]) continue;

			ming_cst[j]=0;

			if(used[par[j]]){

				ming_par[j]=par[j];

			}else{

				int p=par[j];

				while(!used[par[p]]){

					ming_cst[j]+=MOD(cst[p]+add[p]+add[par[p]]);

					p=par[p];

				}

				ming_bef[j]=p;

				ming_par[j]=par[p];

			}

		}

		  

		for(int j=s; j<t; j++){

			if(qry[j].t=='a'){

				add[qry[j].a]+=qry[j].b;

			}else{

				int s=qry[j].a, t=qry[j].b;

				ll ans=0;

				while(s!=t){

					if(dep[s]<dep[t]) swap(s, t);

					int p = ming_par[s];

					if(dep[s]-dep[p]>1){

						int q = ming_bef[s];

						ans+=MOD(add[s]+add[par[s]]+cst[s]);

						ans+=MOD(add[q]+add[par[q]]+cst[q]);

						ans+=ming_cst[s];

					}else{

						ans+=MOD(add[s]+add[p]+cst[s]);

					}

					s=p;

				}

				cout << ans << endl;

			}

		}

	}

}

// Fastest known solution for this problem: