// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



// Hi there, I'm Dondo.  It might be long time no see!

// I managed to solve this last problem by myself, so I removed some 

// stupid macros I used in order to show off this code!

// 

// I put the tree into the array so that each subtree corresponds to a

// subsequence of it.  I want to do two operations to an array: get a value 

// of an element, and add some value to the subsequence of the array.

// In order to do that, I used BIT (=bit<T>) which calculates the 

// cumulative sum of a subsequence (=sbit). 

// I used 3 sbit's : one attains the cost from the root to each vertex (not 

// considering the free path) (=csm), one attains how much you have to minus

// the cost when calculating (=dsm), and one attains the count how many 

// how many changes has been done(=qry).  Please take at look at the code 

// if you want to see the detail. (I don't want to explain the solution in

// English anymore :-) )

//

// Please say hi to everyone.  Bye!

//

// P.S. I didn't use long long to the bit although the cost can be up to

// 10^10, but I've got AC.  Isn't the testcase weak or did I just make

// some mistake in consideration?



// Types ///////////////////////////////////////////////////////////////////////

typedef long long ll;

typedef pair<int, int> pii;

typedef vector<pii> vpii;

 

// Loop & Iteration ////////////////////////////////////////////////////////////

#define FOR(i, a, b) for(int i=a; i<b; i++)

#define REP(i, n) FOR(i, 0, n)



#define PB push_back

#define MP make_pair

 

// BIT /////////////////////////////////////////////////////////////////////////

template<

	typename T = int

>

class bit{

public:

	T *bit_arr;

	int size;

 

	bit(int n){

		size = n;

		bit_arr = new T[n];

		fill(bit_arr, bit_arr+n, 0);

	}

 

	~bit(){

		delete bit_arr;

	}

 

	T sum(int a){

		T ret = 0;

		while(a){

			ret+=bit_arr[a];

			a-=a&-a;

		}

		return ret;

	}

 

	T sum(int a, int b){

		return sum(b)-sum(a);

	}

 

	T get(int a){

		return sum(a, a+1);

	}

 

	void add(int a, T x){

		a++;

		while(a<size){

			bit_arr[a]+=x;

			a+=a&-a;

		}

	}

 

	void set(int a, T x){

		add(a, x-get(a));

	}

};

typedef bit<ll> bll;

 

#define N 112345

#define LO 18

class sbit{

public:

	bit<int> b;

	sbit() : b(N){

	}

	void add(int l, int r, int x){

		b.add(l, x);

		b.add(r, -x);

	}

	int get(int i){

		return b.sum(i+1);

	}

};



int n, k;

vpii path[N];

int f[N]; // original node index -> on the list

int c[N]; // size of subtree

int d[N]; // depth in tree

int p[N][LO]; // parent doubling

// int dmm[N];

sbit csm, dsm, qry;

char buf[10];



void dfs(int nw, int par, int dep, int ind){

	// printf("dfs(nw=%d, par=%d, dep=%d, ind=%d)\n", nw, par, dep, ind);

	f[nw]=ind;

	d[ind]=dep;

	p[ind][0]=par;

	FOR(i, 1, LO) p[ind][i]=p[p[ind][i-1]][i-1];

	int sm=1;

	REP(i, path[nw].size()){

		pii &pr=path[nw][i];

		if(f[pr.first]==par) continue;

		dfs(pr.first, ind, dep+1, ind+sm);

		csm.add(ind+sm, ind+sm+c[ind+sm], pr.second); // <-pr.first?

		if(pr.second%k==0){

			dsm.add(ind+sm, ind+sm+c[ind+sm], pr.second);

			// dmm[ind+sm]=pr.second;

		}

		sm+=c[ind+sm];

	}

	c[ind]=sm;

}



int lsc(int x, int y){

	if(d[x]<d[y]) swap(x, y);

	int dif=d[x]-d[y];

	REP(i, LO) if(dif&(1<<i)) x=p[x][i];

	// printf(" %d %d\n", x, y);

	if(x==y) return x;

	int ret=0;

	for(int i=LO-1; i>=0; i--){

		// printf("(%d, %d)->(%d, %d)\n", x, y, p[x][i], p[y][i]);

		if(p[x][i]==p[y][i]) ret=p[x][i];

		else{

			x=p[x][i];

			y=p[y][i];

		}

	}

	return ret;

}



int clc(int x){

	int q;

	while((q=qry.get(x))){

		int y=x;

		for(int i=LO-1; i>=0; i--){

			if(qry.get(p[y][i])==q) y=p[y][i];

		}

		dsm.add(y, y+c[y], -(dsm.get(y)-dsm.get(p[y][0])));

		int r=csm.get(y)-csm.get(p[y][0]);

		if(r%k==0){

			dsm.add(y, y+c[y], r);

		}

		qry.add(y, y+c[y], -(qry.get(y)-qry.get(p[y][0])));

	}

	return csm.get(x)-dsm.get(x);

}



int main(){

	scanf("%d%d", &n, &k);

	fill(f, f+N, -1);

	// fill(dmm, dmm+N, 0);

	REP(i, n-1){

		int a, b, c;

		scanf("%d%d%d", &a, &b, &c);

		path[a].PB(MP(b, c));

		path[b].PB(MP(a, c));

	}

	dfs(0, 0, 0, 0);

	// REP(i, 20) printf("%2d ", i); LN;

	// REP(i, 20) printf("%2d ", c[i]); LN;

	// REP(i, 20) printf("%2d ", d[i]); LN;

	// REP(i, 20) printf("%2d ", csm.get(i)); LN;

	// REP(i, 20) printf("%2d ", dsm.get(i)); LN;

	int q;

	scanf("%d", &q);

	REP(iqq, q){

		int x, y;

		scanf("%s%d%d", buf, &x, &y);

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

			x=f[x];

			y=f[y];

			int z=lsc(x, y);

			int ans=clc(x)+clc(y)-2*clc(z);

			printf("%d\n", ans);

		}else if(buf[0]=='a'){

			x=f[x];

			if(x){

			 	csm.add(x, x+c[x], y);

				qry.add(x, x+c[x], 1);

			}

			csm.add(x+1, x+c[x], y);

			qry.add(x+1, x+c[x], 1);

		}

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.3559248878731838x):
#include <bits/stdc++.h>

typedef long long L;

using namespace std;



#define int L

#define N 100005

vector<pair<int, L> > path[N];

int par[N], dep[N], siz[N], hev[N];

L cst[N];

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;

    }

}

  

L k;

L add[N];

L edgecost(int a){

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

    return ret%k ? ret : 0;

}

  

int pos[N];

int hl_par[N];

  

L bit[N];

L sum(int i){

    L ret=0;

    while(i){

        ret+=bit[i];

        i-=i&-i;

    }

    return ret;

}

void S(int i, L x){

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

    i++;

    while(i<N){

        bit[i]+=x;

        i+=i&-i;

    }

}

  

L cost(int a, int b){

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

    if(p==q) return abs(sum(pos[a])-sum(pos[b]));

    if(dep[p]<dep[q]){

        swap(p, q);

        swap(a, b);

    }

    return sum(pos[a]) - sum(pos[p])

        + edgecost(p) + cost(par[p], b);

}



main(){

    int n;

    cin >> n >> k;

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

        int a, b;

        L 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++){

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

        int j=i;

        do{

            pos[j]=cnt++;

            hl_par[j]=i;

        }while(j=hev[j]);

    }

 

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

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

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

      

    int q;

    cin >> q;

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

        string s;

        L a, b;

        cin >> s >> a >> b;

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

            add[a]+=b;

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

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

        }else{

            cout << cost(a, b) << endl;

        }

    }

}