#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

struct Edge{
	Edge(int arg_to,ll arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to;
	ll cost;
};

struct Info{

	Info(){
		to_root_sum_cost = 0;
		to_leaf_sum_cost = 0;
		node_sum_cost = 0;
		original_to_root_cost = 0;
	}
	Info(ll arg_to_root_sum_cost,ll arg_to_leaf_sum_cost,ll arg_node_sum_cost,ll arg_original_to_root_cost){
		to_root_sum_cost = arg_to_root_sum_cost;
		to_leaf_sum_cost = arg_to_leaf_sum_cost;
		node_sum_cost = arg_node_sum_cost;
		original_to_root_cost = arg_original_to_root_cost;
	}

	ll to_root_sum_cost,
	   to_leaf_sum_cost,
	   node_sum_cost,
	   original_to_root_cost;
};

struct Data{
	int parent,head,depth,weight;
	ll to_root_cost,sum_add_cost;
};

int V,N;
int root,global_index;
int index_table[NUM];
ll K;
Data data[NUM];
Info  table[8*NUM];
vector<Edge> G[NUM];

void init(int first_N){
	while(N < first_N)N *= 2;
}

void add(int loc,ll value){

	loc += N-1;

	table[loc].to_root_sum_cost += value;
	table[loc].to_leaf_sum_cost += value;

	int parent = (loc-1)/2;
	int left_child,right_child;

	while(true){

		left_child = 2*parent+1;
		right_child = 2*parent+2;

		table[parent].to_root_sum_cost = table[left_child].to_root_sum_cost;
		table[parent].original_to_root_cost = table[left_child].original_to_root_cost;
		table[parent].to_leaf_sum_cost = table[right_child].to_leaf_sum_cost;
		table[parent].node_sum_cost = table[left_child].node_sum_cost+table[right_child].node_sum_cost;

		ll tmp_cost = table[left_child].to_leaf_sum_cost+table[right_child].original_to_root_cost+table[right_child].to_root_sum_cost;

		if(tmp_cost%K != 0){

			table[parent].node_sum_cost += tmp_cost;
		}

		if(parent == 0){

			break;

		}else{

			parent = (parent-1)/2;
		}
	}
}

int makeTree(int node_id,int parent,int depth,ll to_root_cost){

	data[node_id].depth = depth;
	data[node_id].parent = parent;
	data[node_id].to_root_cost = to_root_cost;
	data[node_id].weight = 1;

	int child;

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i].to;
		if(child == parent)continue;

		data[node_id].weight += makeTree(child,node_id,depth+1,G[node_id][i].cost);
	}

	return data[node_id].weight;
}

void HLD(int node_id,int head,int parent){

	index_table[node_id] = global_index++;
	data[node_id].head = head;

	if(G[node_id].size() == 0)return;

	int max_weight = -BIG_NUM;
	int max_node_id = -1,child;

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i].to;
		if(child == parent)continue;

		if(max_weight < data[child].weight){

			max_weight = data[child].weight;
			max_node_id = child;
		}
	}

	if(max_node_id == -1)return;

	HLD(max_node_id,head,node_id);

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i].to;
		if(child == parent || child == max_node_id)continue;

		HLD(child,child,node_id);
	}
}

ll query(int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right)return -1;

	if(search_left <= node_left && search_right >= node_right){
		return table[node_id].node_sum_cost;
	}

	ll left_sum = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	ll right_sum = query(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	int left_child = 2*node_id+1;
	int	 right_child = 2*node_id+2;

	ll tmp_cost = 0;

	if(left_sum != -1 && right_sum != -1){
		tmp_cost = table[left_child].to_leaf_sum_cost+table[right_child].original_to_root_cost+table[right_child].to_root_sum_cost;
	}

	if(tmp_cost%K != 0){

		return left_sum+right_sum+tmp_cost;
	}else{

		return max(0ll,left_sum)+max(0ll,right_sum);
	}
}



int LCA(int a,int b){

	int head_a,head_b;

	while(true){

		head_a = data[a].head;
		head_b = data[b].head;

		if(head_a == head_b){

			if(data[a].depth < data[b].depth){

				return a;
			}else{

				return b;
			}
		}

		if(data[head_a].depth > data[head_b].depth){

			a = data[head_a].parent;
		}else{

			b = data[head_b].parent;
		}
	}
}

ll get_cost(int node_id){

	ll ret = 0;
	ll tmp,add_cost;
	int head_node;

	while(true){

		head_node = data[node_id].head;

		tmp = query(index_table[head_node],index_table[node_id],0,0,N-1);

		ret += tmp;

		if(head_node == root)break;

		add_cost =  data[head_node].to_root_cost
				  + data[head_node].sum_add_cost
				  + data[data[head_node].parent].sum_add_cost;

		if(add_cost%K != 0){

			ret += add_cost;
		}

		node_id = data[head_node].parent;
	}

	return ret;
}

ll send(int from,int to){

	ll A = get_cost(from);
	ll B = get_cost(to);
	ll C = get_cost(LCA(from,to));

	return A+B-2*C;
}

int main(){

	int first_N;

	scanf("%d %lld",&first_N,&K);

	int from,to;
	ll cost;

	for(int loop = 0; loop < first_N-1; loop++){

		scanf("%d %d %lld",&from,&to,&cost);
		G[from].push_back(Edge(to,cost));
		G[to].push_back(Edge(from,cost));
	}

	root = 0;

	makeTree(root,-1,0,0);
	global_index = 0;
	HLD(root,root,-1);

	N = 1;
	init(first_N);

	int tmp_index;

	for(int i = 0; i < first_N; i++){

		tmp_index = index_table[i]+(N-1);
		table[tmp_index].original_to_root_cost = data[i].to_root_cost;
		data[i].sum_add_cost = 0;
	}

	for(int i = 0; i < N; i++){

		add(i,0);
	}

	int num_query;
	scanf("%d",&num_query);

	int node_id;
	char buf[5];

	for(int loop = 0; loop < num_query; loop++){

		scanf("%s",buf);

		if(buf[0] == 'a'){

			scanf("%d %lld",&node_id,&cost);
			add(index_table[node_id],cost);
			data[node_id].sum_add_cost += cost;

		}else{

			scanf("%d %d",&from,&to);
			printf("%lld\n",send(from,to));
		}
	}

	return 0;
}



Measured memory_bytes: 46508