#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<int,ll> pil;
#define F first
#define S second
#define PB push_back
const int N=1e5+10;
int k;
struct BIT{
    vector<ll>v;
    void init(const vector<ll> &val){
        v.resize(val.size()+1);
        ll s[val.size()+1];
        s[0]=0;
        for(int i=0;i<val.size();i++)s[i+1]=s[i]+(val[i]%k==0?0:val[i]);
        v[0]=0;
        for(int i=1;i<v.size();i++)v[i]=s[i]-s[i^(i&-i)];
        return ;
    }
    void add(int n,ll x){
        while(n<v.size()){
            v[n]+=x;
            n+=n&-n;
        }
        return ;
    }
    ll ask(int n){
        ll ans=0;
        while(n){
            ans+=v[n];
            n^=n&-n;
        }
        return ans;
    }
    ll find(int n){return ask(n)-ask(n-1);}
};
vector<pil> graph[N];
int top[N],p[N],dep[N],to[N],size[N];
ll val[N],nv[N];
vector<ll> v[N];
BIT b[N];
void dfs(int now){
    int temp=0;
    to[now]=0;
    nv[now]=0;
    size[now]=1;
    for(pil i:graph[now])if(p[now]!=i.F){
        p[i.F]=now;
        dep[i.F]=dep[now]+1;
        dfs(i.F);
        if(size[i.F]>temp){
            temp=size[i.F];
            to[now]=i.F;
        }
        size[now]+=size[i.F];
    }
}
void init(int now){
    if(to[now]==0)b[top[now]].init(v[top[now]]);
    for(pil i:graph[now])if(p[now]!=i.F){
        if(to[now]==i.F){
            top[i.F]=top[now];
            v[top[now]].PB(i.S);
            val[i.F]=0;
        }
        else {
            top[i.F]=i.F;
            val[i.F]=i.S;
        }
        init(i.F);
    }
    return ;
}
void swap(int &a,int &b){
    int temp=a;
    a=b;
    b=temp;
    return ;
}
void add(int x,int d){
    val[x]+=d;
    nv[x]+=d;
    if(to[x]==0){
        if(top[x]!=x){
            if(v[top[x]][dep[x]-dep[top[x]]-1]%k==0){
                if(d%k!=0)b[top[x]].add(dep[x]-dep[top[x]],d+v[top[x]][dep[x]-dep[top[x]]-1]);
            }
            else if((v[top[x]][dep[x]-dep[top[x]]-1]+d)%k==0)b[top[x]].add(dep[x]-dep[top[x]],-v[top[x]][dep[x]-dep[top[x]]-1]);
            else b[top[x]].add(dep[x]-dep[top[x]],d);
            v[top[x]][dep[x]-dep[top[x]]-1]+=d;
        }
    }
    else if(top[x]==x){
        if(v[top[x]][dep[x]-dep[top[x]]]%k==0){
            if(d%k!=0)b[top[x]].add(dep[x]-dep[top[x]]+1,d+v[top[x]][dep[x]-dep[top[x]]]);
        }
        else if((v[top[x]][dep[x]-dep[top[x]]]+d)%k==0)b[top[x]].add(dep[x]-dep[top[x]]+1,-v[top[x]][dep[x]-dep[top[x]]]);
        else b[top[x]].add(dep[x]-dep[top[x]]+1,d);
        v[top[x]][dep[x]-dep[top[x]]]+=d;
    }
    else{
        if(v[top[x]][dep[x]-dep[top[x]]-1]%k==0){
            if(d%k!=0)b[top[x]].add(dep[x]-dep[top[x]],d+v[top[x]][dep[x]-dep[top[x]]-1]);
        }
        else if((v[top[x]][dep[x]-dep[top[x]]-1]+d)%k==0)b[top[x]].add(dep[x]-dep[top[x]],-v[top[x]][dep[x]-dep[top[x]]-1]);
        else b[top[x]].add(dep[x]-dep[top[x]],d);
        v[top[x]][dep[x]-dep[top[x]]-1]+=d;
        
        if(v[top[x]][dep[x]-dep[top[x]]]%k==0){
            if(d%k!=0)b[top[x]].add(dep[x]-dep[top[x]]+1,d+v[top[x]][dep[x]-dep[top[x]]]);
        }
        else if((v[top[x]][dep[x]-dep[top[x]]]+d)%k==0)b[top[x]].add(dep[x]-dep[top[x]]+1,-v[top[x]][dep[x]-dep[top[x]]]);
        else b[top[x]].add(dep[x]-dep[top[x]]+1,d);
        v[top[x]][dep[x]-dep[top[x]]]+=d;
    }
    return ;
}
long long int query(int l,int r){
    long long int ans=0;
    while(l!=r){
        if(top[l]==top[r]){
            if(dep[l]>dep[r])swap(l,r);
            ans+=b[top[l]].ask(dep[r]-dep[top[l]])-b[top[l]].ask(dep[l]-dep[top[l]]);
            break;
        }
        else{
            if(dep[top[l]]<dep[top[r]])swap(l,r);
            ans+=b[top[l]].ask(dep[l]-dep[top[l]]);
            if((val[top[l]]+nv[p[top[l]]])%k!=0)ans+=val[top[l]]+nv[p[top[l]]];
            l=p[top[l]];
        }
    }
    return ans;
}
int main(){
    int n,q,a,b,c;
    string s;
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++){
        scanf("%d%d%d",&a,&b,&c);
        graph[a].PB({b,c});
        graph[b].PB({a,c});
    }
    top[0]=0;
    p[0]=-1;
    dep[0]=0;
    dfs(0);
    init(0);
    scanf("%d",&q);
    while(q--){
        cin>>s>>a>>b;
        if(s[0]=='a')add(a,b);
        else printf("%lld\n",query(a,b));
    }
}



Measured memory_bytes: 28364