#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
class Segtree{
  public:
  ll n,*dat;
  void init(ll nn){
      n=nn;
      dat=new ll[2*n];
      for(int i=0;i<2*n;i++)dat[i]=0;
  }
  void upd(ll i,ll x){
   i+=n; dat[i]=x;
   for(;i;i>>=1){
    dat[i/2]=dat[i]+dat[i^1];   
   }
  }
  ll qry(ll l,ll r){
   l+=n,r+=n+1;
   ll res=0;
   for(ll a=l,b=r;a<b;a>>=1,b>>=1){
    if(a&1)res+=dat[a++];
    if(b&1)res+=dat[--b];
   }
   return res;
  }
};

#define N 100010
ll n,mo;
vector<ll> g[N];
ll t[N];
unordered_map<ll,ll> e[N];
vector<ll> f[N];

namespace hld{
  ll siz[N],dep[N];
  void dfs(ll x,ll from,ll d){
      siz[x]=1; dep[x]=d;
      for(auto y:g[x])if(y!=from){
          dfs(y,x,d+1);
          siz[x]+=siz[y];
      }
  }
  ll chain[N],id[N];
  vector<ll> par,len,head;
  Segtree seg[N];
  void init(){
      for(int i=1;i<=n;i++)dep[i]=chain[i]=-1;
      for(int i=1;i<=n;i++){
       if(~dep[i])continue;
       dfs(i,0,0);
      }
      P dat[N];
      for(int i=1;i<=n;i++){
       dat[i-1]=make_pair(dep[i],i);   
      }
      sort(dat,dat+n);
      ll m=0;
      for(int i=0;i<n;i++){
       ll s=dat[i].second;
       if(~chain[s])continue;
       ll pp=0;
       for(auto y:g[s])if(~chain[y])pp=y;
       par.push_back(pp); len.push_back(0); head.push_back(s);
       for(ll k=0;;k++){
        len[m]=k;
        chain[s]=m,id[s]=k;
        ll ma=-1,pnt=-1;
        for(auto y:g[s]){
         if(~chain[y])continue;
         if(ma<siz[y]){
          ma=siz[y],pnt=y;   
         }
        }
        if(pnt==-1)break;
        f[s].push_back(pnt);
        f[pnt].push_back(s);
        s=pnt;
       }
       m++;
      }
      for(int i=0;i<m;i++){
          seg[i].init(len[i]+3);
      }
  }
  ll edgelen(ll a,ll b){
   ll res=e[a][b];
   res+=t[a]+t[b];
   if(res%mo==0)return 0;
   return res;
  }
  ll qry(ll a,ll b){
      ll res=0;
      while(chain[a]!=chain[b]){
         if(chain[a]<chain[b])swap(a,b);
         res+=seg[chain[a]].qry(1,id[a]); //cout<<"#"<<head[chain[a]]<<" "<<a<<" "<<seg[chain[a]].qry(1,id[a])<<endl;
         res+=edgelen(head[chain[a]],par[chain[a]]);// cout<<"%"<<head[chain[a]]<<" "<<par[chain[a]]<<endl;
         a=par[chain[a]];
      }
      if(id[a]>id[b])swap(a,b);
      res+=seg[chain[a]].qry(id[a]+1,id[b]);
    //cout<<a<<" "<<b<<" "<<seg[chain[a]].qry(id[a]+1,id[b])<<endl;
      return res;
  }
  void upd(ll a,ll x){
      t[a]+=x;
      for(auto b:f[a]){
       ll ee=edgelen(a,b);
       ll ie=min(id[a],id[b]);
       seg[chain[a]].upd(ie+1,ee);
      }
  }
};
int main(){
    cin>>n>>mo;
    for(int i=0;i<n-1;i++){
     ll a,b,c;cin>>a>>b>>c; a++,b++;
     e[a][b]=e[b][a]=c;
     g[a].push_back(b);
     g[b].push_back(a);
    }
    hld::init();
    //for(int i=1;i<=n;i++)cout<<i-1<<":"<<hld::chain[i]<<" "<<hld::id[i]<<endl;
    for(int i=1;i<=n;i++){
     t[i]=0;
     hld::upd(i,0);
    }
  //cout<<"-----"<<hld::edgelen(1,3)<<endl;
    ll q;cin>>q;
    while(q--){
     string s; ll a,b;cin>>s>>a>>b;
     if(s=="add"){
         a++;
         hld::upd(a,b);
     }
     if(s=="send"){
         a++,b++;
      cout<<hld::qry(a,b)<<endl;   
     }
    }
 return 0;   
}


Measured memory_bytes: 43692