#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

struct SegmentTree{
   private:
       int n;
       vector<ll> node;
   public:
       SegmentTree(int sz,ll init){
           n=1;
           while(n<sz)n*=2;
           node.resize(2*n-1,init);
       }
       void update(int k,ll x){
           k+=n-1;
           node[k]=x;
           while(k>0){
               k=(k-1)/2;
               node[k]=node[2*k+1]+node[2*k+2];
           }
       }
       //[a,b)での和を返す
       ll get(int a,int b,int k=0,int l=0,int r=-1){
           if(r<0)r=n;
           if(r<=a||b<=l)return 0;
           if(a<=l&&r<=b)return node[k];
           ll xl=get(a,b,2*k+1,l,(l+r)/2);
           ll xr=get(a,b,2*k+2,(l+r)/2,r);
           return xl+xr;
       }
   };

SegmentTree sg(101010,0);
ll k,e[101010],a[101010];

struct HLDecomposition{
    int n,pos;
    vector<vector<int>> v;
    vector<int> idx,head,sz,hvy,par,depth,inv,type;

    HLDecomposition(){};
    HLDecomposition(int s):
        n(s),pos(0),v(n),idx(n,-1),head(n),sz(n,1),
        hvy(n,-1),par(n),depth(n),inv(n),type(n){}
    
    void addedge(int x,int y){
        v[x].push_back(y);
        v[y].push_back(x);
    }

    void dfs1(int rt){
        par[rt]=-1;
        depth[rt]=0;
        stack<pint> st;
        st.push({rt,0});
        while(!st.empty()){
            int x=st.top().first;
            int& i=st.top().second;
            if(i<(int)v[x].size()){
                int to=v[x][i++];
                if(to==par[x])continue;
                par[to]=x;
                depth[to]=depth[x]+1;
                st.push({to,0});
            }
            else {
                st.pop();
                int res=0;
                for(int to:v[x]){
                    if(to==par[x])continue;
                    sz[x]+=sz[to];
                    if(sz[to]>res)res=sz[to],hvy[x]=to;
                }
            }
        }
    }
    void dfs2(int r,int c){
        int &k=pos;
        stack<int> st;
        st.push(r);
        while(!st.empty()){
            int h=st.top();st.pop();
            for(int x=h;x!=-1;x=hvy[x]){
                type[x]=c;
                head[x]=h;
                idx[x]=k++;
                inv[idx[x]]=x;
                for(int to:v[x])
                    if(to!=par[x]&&to!=hvy[x])st.push(to);
            }
        }
    }

    void build(vector<int> rs=vector<int>(1,0)){
        int c=0;
        for(int r:rs){
            dfs1(r);
            dfs2(r,c++);
        }
    }
    ll f(int x,int y){
        //ここに何か書く！！！
        return sg.get(x,y+1);
    }

    void for_v(int x,int y){
        while(1){
            if(idx[x]>idx[y])swap(x,y);
            f(max(idx[head[y]],idx[x]),idx[y]);
            if(head[x]!=head[y])y=par[head[y]];
            else break;
        }
    }

    ll for_edge(int x,int y){
        ll ret=0;
        while(1){
            if(idx[x]>idx[y])swap(x,y);
            if(head[x]!=head[y]){
                ret+=f(idx[head[y]]+1,idx[y]);
                y=head[y];
                ll res=e[idx[y]]+a[y]+a[par[y]];
                if(res%k)ret+=res;
                y=par[y];
            }
            else{
                if(x!=y)ret+=f(idx[x]+1,idx[y]);
                break;
            }
        }
        return ret;
    }

    void add(int x,ll y){
        a[x]+=y;
        if(head[x]!=x){
            e[idx[x]]+=y;
            if(e[idx[x]]%k){
                sg.update(idx[x],e[idx[x]]);
            }
            else sg.update(idx[x],0);
        }
        if(hvy[x]!=-1){
            int p=idx[x]+1;
            e[p]+=y;
            if(e[p]%k){
                sg.update(p,e[p]);
            }
            else sg.update(p,0);
        }
    }
    int lca(int x,int y){
        while(1){
            if(idx[x]>idx[y])swap(x,y);
            if(head[x]==head[y])return x;
            y=par[head[y]];
        }
    }

    int dist(int x,int y){
        return depth[x]+depth[y]-2*depth[lca(x,y)];
    }
};


int main(){
    int n;cin>>n>>k;
    HLDecomposition hl(n);
    int x[n-1],y[n-1],z[n-1];
    rep(i,n-1){
        cin>>x[i]>>y[i]>>z[i];
        hl.addedge(x[i], y[i]);
    }
    hl.build();
    rep(i,n-1){
        int v=max(hl.idx[x[i]],hl.idx[y[i]]);
        if(z[i]%k)sg.update(v,z[i]);
        e[v]=z[i];
    }
    int q;cin>>q;
    while(q--){
        string s;
        int u,v;
        cin>>s>>u>>v;
        if(s=="send"){
            cout<<hl.for_edge(u,v)<<endl;
        }
        else {
            hl.add(u,v);
        }
    }
}


Measured memory_bytes: 16456