#include<bits/stdc++.h>
using namespace std;
using Int = long long;

struct HLDecomposition {
  int n,pos;
  vector<vector<int> > G;
  vector<int> vid, head, sub, hvy, par, dep, inv, type, ps, pt;
  
  HLDecomposition(){}
  HLDecomposition(int sz):
    n(sz),pos(0),G(n),
    vid(n,-1),head(n),sub(n,1),hvy(n,-1),
    par(n),dep(n),inv(n),type(n),ps(n),pt(n){}
  
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void build(vector<int> rs={0}) {
    int c=0;
    for(int r:rs){
      dfs(r);
      bfs(r, c++);
    }
  }
  
  void dfs(int rt) {
    using T = pair<int, int>;
    stack<T> st;
    par[rt]=-1;
    dep[rt]=0;
    st.emplace(rt,0);
    while(!st.empty()){
      int v=st.top().first;
      int &i=st.top().second;
      if(i<(int)G[v].size()){
	int u=G[v][i++];
	if(u==par[v]) continue;
	par[u]=v;
	dep[u]=dep[v]+1;
	st.emplace(u,0);
      }else{
	st.pop();
	for(int j=0;j<(int)G[v].size();j++){
	  int &u=G[v][j];
	  if(u==par[v]) swap(u,G[v].back());
	  if(u==par[v]) continue;
	  sub[v]+=sub[u];
	  if(sub[u]>sub[G[v].front()]) swap(u,G[v].front());
	}
      }
    }
  }

  void bfs(int r,int c) {
    using T = tuple<int, int, int>;
    stack<T> st;
    st.emplace(r,r,0);
    while(!st.empty()){
      int v,h;
      tie(v,h,ignore)=st.top();
      int &i=get<2>(st.top());
      if(!i){
	type[v]=c;
	ps[v]=vid[v]=pos++;
	inv[vid[v]]=v;
	head[v]=h;
        hvy[v]=(G[v].empty()?-1:G[v][0]);
	if(hvy[v]==par[v]) hvy[v]=-1;
      }
      if(i<(int)G[v].size()){
	int u=G[v][i++];
	if(u==par[v]) continue;
	st.emplace(u,(hvy[v]==u?h:u),0);
      }else{
	st.pop();
	pt[v]=pos;
      }
    }
  }
  
  // for_each(vertex)
  // [l,r] <- attention!!
  void for_each(int u, int v, const function<void(int, int)>& f) {
    while(1){
      if(vid[u]>vid[v]) swap(u,v);
      f(max(vid[head[v]],vid[u]),vid[v]);
      if(head[u]!=head[v]) v=par[head[v]];
      else break;
    }
  }

  template<typename T,typename Q,typename F>
  T for_each(int u,int v,T ti,const Q &q,const F &f){
    T l=ti,r=ti;
    while(1){
      if(vid[u]>vid[v]){
	swap(u,v);
	swap(l,r);
      }
      l=f(l,q(max(vid[head[v]],vid[u]),vid[v]));
      if(head[u]!=head[v]) v=par[head[v]];
      else break;
    }
    return f(l,r);
  }
  
  // for_each(edge)
  // [l,r] <- attention!!
  void for_each_edge(int u, int v, const function<void(int, int)>& f) {
    while(1){
      if(vid[u]>vid[v]) swap(u,v);
      if(head[u]!=head[v]){
	f(vid[head[v]],vid[v]);
        v=par[head[v]];
      }else{
	if(u!=v) f(vid[u]+1,vid[v]);
	break;
      }
    }
  }

  int lca(int u,int v){
    while(1){
      if(vid[u]>vid[v]) swap(u,v);
      if(head[u]==head[v]) return u;
      v=par[head[v]];
    }
  }

  int distance(int u,int v){
    return dep[u]+dep[v]-2*dep[lca(u,v)];
  }
};


template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  int n;
  F f;
  G g;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T ti):
    f(f),g(g),ti(ti){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(int a,int b){
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }

  int find(int a,int b,function<bool(T)> &check,int k,int l,int r){
    if(!check(dat[k])||r<=a||b<=l) return -1;
    if(k>=n-1) return k-(n-1);
    int m=(l+r)>>1;
    int vl=find(a,b,check,k*2+1,l,m);
    if(~vl) return vl;
    return find(a,b,check,k*2+2,m,r);
  }
  
  int find(int a,int b,function<bool(T)> &check){
    return find(a,b,check,0,0,n);
  }
  
};

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  scanf("%lld %lld",&n,&k);
  HLDecomposition hld(n);
  vector<map<Int,Int> > m(n);
  for(Int i=0;i<n-1;i++){
    Int a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    hld.add_edge(a,b);
    m[a][b]=m[b][a]=c;
  }
  hld.build();

  vector<Int> w(n,0);  
  auto mget=[&](Int a,Int b){
    if(!m[a].count(b)) return 0LL;
    Int res=w[a]+w[b]+m[a][b];
    if(res%k) return res;
    return 0LL;
  };
  
  using T = tuple<Int, Int, Int>;
  auto f=[&](T a,T b){
    if(a>b) swap(a,b);
    Int al,ar,av;
    tie(al,ar,av)=a;
    Int bl,br,bv;
    tie(bl,br,bv)=b;
    if(al<0||ar<0) return b;
    Int cl,cr,cv=av+bv;
    if(m[al].count(bl)){
      cl=ar;cr=br;
      cv+=mget(al,bl);
    }else if(m[al].count(br)){
      cl=ar;cr=bl;
      cv+=mget(al,br);
    }else if(m[ar].count(bl)){
      cl=al;cr=br;
      cv+=mget(ar,bl);
    }else if(m[ar].count(br)){
      cl=al;cr=bl;
      cv+=mget(ar,br);
    }else{
      cl=cr=cv=-1;
    }
    return T(cl,cr,cv);
  };
  
  SegmentTree<T, Int> seg(n,f,
			 [&](T a,Int b){
			   return T(b,b,0);
			 },
			 T(-1,-1,0));
  for(Int i=0;i<n;i++) seg.update(i,hld.inv[i]);
  
  Int q;
  cin>>q;
  char buf[256];
  while(q--){
    scanf(" %s ",buf);
    string op(buf);
    
    if(op=="add"){
      Int x,d;
      scanf("%lld %lld",&x,&d);
      w[x]+=d;
      seg.update(hld.vid[x],x);
    }
    
    if(op=="send"){
      Int s,t;
      scanf("%lld %lld",&s,&t);
      auto ask=[&](int l,int r){return seg.query(l,r+1);};
      T v=hld.for_each(s,t,seg.ti,ask,seg.f);
      printf("%lld\n",get<2>(v));
    }
  }
  return 0;
}



Measured memory_bytes: 36796