#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

// -------------------------------- 変数 -------------------------------

const int BACKET = 300;

int N, A[1 << 17], B[1 << 17], C[1 << 17];
int K;
int Q, T2[1 << 17], T3[1 << 17]; string T1[1 << 17];
int par[1 << 17], weight[1<<17], dist[1 << 17], prev_[1 << 17][22];
int cl[1 << 17], cr[1 << 17], cntv;
int dp[1 << 17];
bool used[1 << 17], weighted[1 << 17];
long long added[1 << 17], answer[1 << 17];

vector<pair<int, int>> X[1 << 17];
vector<int> Y;

// -------------------------------- 関数 -------------------------------

// 1. 入力
void Input() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= N - 1; i++) scanf("%d%d%d", &A[i], &B[i], &C[i]);
	scanf("%d", &Q);
	for (int i = 1; i <= Q; i++) { cin >> T1[i]; scanf("%d%d", &T2[i], &T3[i]); }
}

// 2. 深さ優先探索
void dfs(int pos, int dep) {
	Y.push_back(pos);
	used[pos] = true;
	dist[pos] = dep;
	cntv++; cl[pos] = cntv;
	for (int i = 0; i < X[pos].size(); i++) {
		int to = X[pos][i].first;
		if (used[to] == true) continue;
		par[to] = pos;
		weight[to] = X[pos][i].second;
		dfs(to, dep + 1);
	}
	cr[pos] = cntv;
}

// 3. 設定
void Initialize() {
	for (int i = 1; i <= N - 1; i++) {
		X[A[i]].push_back(make_pair(B[i], C[i]));
		X[B[i]].push_back(make_pair(A[i], C[i]));
	}

	dfs(0, 0);

	for (int i = 0; i <= N - 1; i++) prev_[i][0] = par[i];
	for (int i = 0; i <= 20; i++) {
		for (int j = 0; j <= N - 1; j++) prev_[j][i + 1] = prev_[prev_[j][i]][i];
	}

	for (int i = 0; i <= N - 1; i++) dp[i] = -1;
	for (int i = 0; i <= N - 1; i++) {
		if (X[i].size() >= BACKET) { weighted[i] = true; dp[i] = i; }
	}

	for (int i = 0; i < Y.size(); i++) {
		int pos = Y[i];
		for (int j = 0; j < X[pos].size(); j++) {
			int to = X[pos][j].first;
			if (dist[to] <= dist[pos] || dp[to] >= 0) continue;
			dp[to] = dp[pos];
		}
	}
	par[0] = -1;
}

// 4. LCA 関連の関数
int prevs(int pos, int x) {
	for (int i = 18; i >= 0; i--) {
		if (x >= (1 << i)) { pos = prev_[pos][i]; x -= (1 << i); }
	}
	return pos;
}

int lca(int u, int v) {
	if (dist[u] > dist[v]) swap(u, v);
	v = prevs(v, dist[v] - dist[u]);
	if (u == v) return u;

	for (int i = 18; i >= 0; i--) {
		if (prev_[u][i] != prev_[v][i]) {
			u = prev_[u][i];
			v = prev_[v][i];
		}
	}
	return prev_[u][0];
}

// 5. 重い辺の列挙
vector<int> enumerate_weighted(int u, int v) {
	int x = lca(u, v);

	vector<int> I; int pos = dp[u];
	while (dist[pos] >= dist[x] && pos != -1) {
		if (pos != x) I.push_back(pos);
		if (pos != u) I.push_back(prevs(u, dist[u] - dist[pos] - 1));
		pos = par[pos]; if (pos >= 0) pos = dp[pos];
	}

	pos = dp[v];
	while (dist[pos] >= dist[x] && pos != -1) {
		if (pos != x) I.push_back(pos);
		if (pos != v) I.push_back(prevs(v, dist[v] - dist[pos] - 1));
		pos = par[pos]; if (pos >= 0) pos = dp[pos];
	}

	sort(I.begin(), I.end());

	vector<int> J;
	for (int i = 0; i < I.size(); i++) {
		if (i == 0 || I[i] != I[i - 1]) J.push_back(I[i]);
	}
	return J;
}

// 6. Binary Indexed Tree
class BIT {
public:
	vector<long long> dat;
	int size_ = 0;

	void init(int sz) {
		size_ = sz + 2;
		dat.resize(size_ + 2, 0);
	}
	void add(int pos, long long x) {
		pos++;
		while (pos <= size_) {
			dat[pos] += x;
			pos += (pos & -pos);
		}
	}
	long long sum(int pos) {
		pos++; long long s = 0;
		while (pos >= 1) {
			s += dat[pos];
			pos -= (pos&-pos);
		}
		return s;
	}
};

// 7. クエリに答える
void AnswerQuery() {
	BIT Z; Z.init(N + 2);
	
	for (int i = 1; i <= N - 1; i++) {
		if (weighted[i] == false && weighted[par[i]] == false && weight[i] % K != 0) {
			Z.add(cl[i], weight[i]);
			Z.add(cr[i] + 1, -weight[i]);
		}
	}

	for (int i = 1; i <= Q; i++) {
		if (T1[i] == "add") {
			added[T2[i]] += 1LL * T3[i];

			if (weighted[T2[i]] == false) {
				for (pair<int, int> j : X[T2[i]]) {
					int u = j.first, v = T2[i];
					if (weighted[u] == true || weighted[v] == true) continue;
					if (dist[u] > dist[v]) swap(u, v);

					long long costb = added[u] + added[v] + 1LL * j.second;
					long long costa = costb - 1LL * T3[i];
					if (costb%K == 0) costb = 0;
					if (costa%K == 0) costa = 0;

					Z.add(cl[v], costb - costa);
					Z.add(cr[v] + 1, costa - costb);
				}
			}
		}
		else {
			int u = T2[i], v = T3[i], x = lca(T2[i], T3[i]);
			long long cost1 = Z.sum(cl[u]) + Z.sum(cl[v]) - 2LL * Z.sum(cl[x]);

			vector<int> F = enumerate_weighted(u, v);
			for (int pos : F) {
				long long v = (added[pos] + added[par[pos]] + weight[pos]);
				if (v%K == 0) v = 0;
				cost1 += v;
			}

			answer[i] = cost1;
		}
	}
}

int main() {
	Input();
	Initialize();
	AnswerQuery();
	for (int i = 1; i <= Q; i++) {
		if (T1[i] == "send") printf("%lld\n", answer[i]);
	}
	return 0;
}


Measured memory_bytes: 35040