#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;
  
  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){}
  
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void build(vector<int> rs=vector<int>(1,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();
	int res=0;
	for(int u:G[v]){
	  if(u==par[v]) continue;
	  sub[v]+=sub[u];
	  if(res<sub[u]) res=sub[u],hvy[v]=u;
	}
      }
    }
  }

  void bfs(int r,int c) {
    int &k=pos;
    queue<int> q({r});
    while(!q.empty()){
      int h=q.front();q.pop();
      for(int i=h;i!=-1;i=hvy[i]) {
	type[i]=c;
	vid[i]=k++;
	inv[vid[i]]=i;
	head[i]=h;
	for(int j:G[i])
	  if(j!=par[i]&&j!=hvy[i]) q.push(j);
      }
    }
  }
  
  // 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;
    }
  }
  
  // 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{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  Int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(Int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(Int)v.size()) build(n_,v);
  }
  void init(Int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  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=d1,vr=d1;
    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);
  }
  
};

signed main(){
  Int n,k;
  cin>>n>>k;
  HLDecomposition hld(n);
  using P = pair<Int,int>;
  map<P,Int> m;
  for(Int i=0;i<n-1;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    hld.add_edge(a,b);
    m[P(a,b)]=m[P(b,a)]=c;
  }
  hld.build();
  vector<Int> w(n,0);
  using T = tuple<Int, Int, Int>;
  auto mget=[&](Int a,Int b){
    if(!m.count(P(a,b))) return 0LL;
    Int res=w[a]+w[b]+m[P(a,b)];
    if(res%k) return res;
    return 0LL;
  };
  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.count(P(al,bl))){
      cl=ar;cr=br;
      cv+=mget(al,bl);
    }else if(m.count(P(al,br))){
      cl=ar;cr=bl;
      cv+=mget(al,br);
    }else if(m.count(P(ar,bl))){
      cl=al;cr=br;
      cv+=mget(ar,bl);
    }else if(m.count(P(ar,br))){
      cl=al;cr=bl;
      cv+=mget(ar,br);
    }else{
      //cout<<al<<" "<<ar<<":"<<bl<<" "<<br<<endl;
      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;
  while(q--){
    string op;
    cin>>op;
    if(op=="add"){
      Int x,d;
      cin>>x>>d;
      w[x]+=d;
      seg.update(hld.vid[x],x);
    }
    if(op=="send"){
      Int s,t;
      cin>>s>>t;
      vector<T> v;
      hld.for_each(s,t,
		   [&](Int l,Int r){
		     v.push_back(seg.query(l,r+1));
		   });

      //for(T x:v) print(x);
      while((Int)v.size()>1){
	T x=v.back();v.pop_back();
	bool fl=0;
	for(Int i=0;i<(Int)v.size();i++){
	  T y=f(x,v[i]);
	  if(~get<0>(y)){
	    v[i]=y;
	    fl=1;
	    break;
	  }
	}
	assert(fl);
      }
      assert((Int)v.size()==1);
      cout<<(get<2>(v.front()))<<endl;
    }
    //cout<<"m"<<mget(0,2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 31396