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

struct HLDecomposition {
  Int n,pos;
  vector<vector<Int> > G;
  vector<Int> vid, head, heavy, parent, depth, inv, type;
  
  HLDecomposition(){}
  HLDecomposition(Int sz):
    n(sz),pos(0),G(n),
    vid(n,-1),head(n),heavy(n,-1),parent(n),depth(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, -1);
      bfs(r, c++);
    }
  }
  
  using T = tuple<Int,int,Int,int,Int,int>;
  Int dfs(Int curr,Int prev) {
    stack<T> st;
    Int result;
    Int sub,max_sub,i,next;
  ENTRYPOINT:
    parent[curr] = prev;
    sub=1;
    max_sub=0;
    for(i=0;i<(Int)G[curr].size();i++){
      next=G[curr][i];
      if(next!=prev) {
	depth[next]=depth[curr]+1;
	{
	  st.emplace(curr,prev,sub,max_sub,i,next);
	  prev=curr;curr=next;
	  goto ENTRYPOINT;
	}
      RETURNPOINT:
	T t=st.top();st.pop();
	tie(curr,prev,sub,max_sub,i,next)=t;
	
	Int sub_next=result;
	sub+=sub_next;
	if(max_sub<sub_next)
	  max_sub=sub_next,heavy[curr]=next;
      }
    }
    while(!st.empty()){
      result=sub;
      goto RETURNPOINT;
    }
    return sub;
  }

  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=heavy[i]) {
	type[i]=c;
	vid[i]=k++;
	inv[vid[i]]=i;
	head[i]=h;
	for(Int j:G[i])
	  if(j!=parent[i]&&j!=heavy[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=parent[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=parent[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=parent[head[v]];
    }
  }

  Int distance(Int u,Int v){
    return depth[u]+depth[v]-2*depth[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){
		     T x=seg.query(l,r+1);
		     for(Int i=0;i<(Int)v.size();i++){
		       T y=f(x,v[i]);
		       if(~get<0>(y)){
			 v[i]=y;
			 return;
		       }
		     }
		     v.push_back(x);
		   });

      //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: 34164