#include <bits/stdc++.h>
using namespace std;
template< typename G >
 
struct DoublingLowestCommonAncestor {
    const int LOG;
    vector< int > dep;
    const G &g;
    vector< vector< int > > table;
 
    DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) {
        table.assign(LOG, vector< int >(g.size(), -1));
    }
 
    void dfs(int idx, int par, int d) {
        table[0][idx] = par;
        dep[idx] = d;
        for(auto &to : g[idx]) {
            if(to != par) dfs(to, idx, d + 1);
        }
    }
 
    void build() {
        dfs(0, -1, 0);
        for(int k = 0; k + 1 < LOG; k++) {
            for(int i = 0; i < table[k].size(); i++) {
                if(table[k][i] == -1) table[k + 1][i] = -1;
                else table[k + 1][i] = table[k][table[k][i]];
            }
        }
    }
 
    int query(int u, int v) {
        if(dep[u] > dep[v]) swap(u, v);
        for(int i = LOG - 1; i >= 0; i--) {
            if(((dep[v] - dep[u]) >> i) & 1) v = table[i][v];
        }
        if(u == v) return u;
        for(int i = LOG - 1; i >= 0; i--) {
            if(table[i][u] != table[i][v]) {
                u = table[i][u];
                v = table[i][v];
            }
        }
        return table[0][u];
    }
};
 
#define BOUND 300
#define int long long
int k;
 
vector<pair<int, int> > graph[100010];
vector<vector<int> > tree(100010);
 
 
vector<pair<int, pair<int, int> > > query[2000];
 
int dist[100010] = {};
int kdist[100010] = {};
 
bool used[100010] = {};
int parent[100010] = {};
 
void makeTree(int idx){
    used[idx] = true;
 
    for(int i = 0;i < graph[idx].size();i++){
        int ko = graph[idx][i].first;
        if(!used[ko]){
            dist[ko] = graph[idx][i].second;
            tree[idx].push_back(ko);
            parent[ko] = idx;
            makeTree(ko);
        }
    }
 
    return;
}
 
vector<pair<int, pair<int, int> > > subTree[2000];
int ditbl[2000][2000] = {};
int ddtbl[2000][2000] = {};
int cidx[100010];
int cp = 1;
int uidx[100010];
 
void makeSubTree(int idx, int par, int d, int o, int di){
 
    if((dist[idx] + o) % k != 0){
        d += dist[idx] + o;
    }
 
    bool flag = false;
    if(uidx[idx]){
        if(par != idx){
            cidx[idx] = cp;
            subTree[cidx[idx]].clear();
            if(parent[idx] != par){
                subTree[cidx[idx]].push_back(make_pair(cidx[par], make_pair(-1, dist[idx]+o)));
                subTree[cidx[par]].push_back(make_pair(cidx[idx], make_pair(-1, di)));
            }else{
                int ki, oi;
                ki = subTree[cidx[par]].size();
                oi = subTree[cidx[idx]].size();
                subTree[cidx[idx]].push_back(make_pair(cidx[par], make_pair(ki, dist[idx]+o)));
                subTree[cidx[par]].push_back(make_pair(cidx[idx], make_pair(oi, di)));
            }
            ditbl[cidx[idx]][cidx[par]] = d;
            ditbl[cidx[par]][cidx[idx]] = d;
            cp++;
            d = 0;
            par = idx;
 
        }
 
        di = kdist[idx];
        flag = true;
    }
 
    for(int i = 0;i < tree[idx].size();i++){
        makeSubTree(tree[idx][i], par, d, kdist[idx], flag ? di+dist[tree[idx][i]] : di);
    }
}
 
int bfs(int s, int t){
    s = cidx[s];
    t = cidx[t];
 
    bool used[2000] = {};
 
    queue<pair<int, int> > que;
    que.push(make_pair(s, 0));
    used[s] = 1;
 
    while(!que.empty()){
        int idx = que.front().first;
        int cost = que.front().second;
 
        que.pop();
 
        if(idx == t){
            return cost;
        }
 
        used[idx] = 1;
 
        for(int i = 0;i < subTree[idx].size();i++){
            int next = subTree[idx][i].first;
            int ncost = ditbl[idx][next];
            if(!used[next]){
                que.push(make_pair(next, ncost+cost));
            }
        }
    }
 
    return 0;
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n >> k;
 
    int a, b, c;
    for(int i = 0;i < n-1;i++){
        cin >> a >> b >> c;
        graph[a].push_back(make_pair(b, c));
        graph[b].push_back(make_pair(a, c));
    }
 
    int Q, q;
 
    cin >> Q;
    string str;
    for(int i = 0;i < Q;i++){
        cin >> str >> b >> c;
        //send : 1
        //add : 2
        query[i/BOUND].push_back(make_pair(str[0] == 's' ? 1 : 2, make_pair(b, c)));
    }
 
 
    q = (Q+BOUND-1)/BOUND;
 
    makeTree(0);
 
    DoublingLowestCommonAncestor<vector<vector<int> > > d(tree);
    d.build();
 
    for(int p = 0;p < q;p++){
        subTree[0].clear();
        cidx[0] = 0;
        memset(uidx, false, sizeof(uidx));
        uidx[0] = true;
        cp = 1;
 
        for(int i = 0;i < query[p].size();i++){
            if(query[p][i].first == 1){
                uidx[query[p][i].second.first] = true;
                uidx[query[p][i].second.second] = true;
                uidx[d.query(query[p][i].second.first, query[p][i].second.second)] = true;
            }else{
                uidx[query[p][i].second.first] = true;
            }
        }
 
        makeSubTree(0, 0, 0, 0, 0);
 
 
        for(int i = 0;i < query[p].size();i++){
            a = query[p][i].second.first;
            b = query[p][i].second.second;
 
            if(query[p][i].first == 1){
                cout << bfs(a, b) << endl;
            }else{
                if(a != 0) dist[a] += b;
                kdist[a] += b;
                a = cidx[a];
                for(int j = 0;j < subTree[a].size();j++){
                    int old = subTree[a][j].second.second;
                    if(old % k == 0) old = 0;
 
                    ditbl[a][subTree[a][j].first] -= old;
                    ditbl[subTree[a][j].first][a] -= old;
 
                    subTree[a][j].second.second += b;
                    if(subTree[a][j].second.first != -1){
                        subTree[subTree[a][j].first][subTree[a][j].second.first].second.second += b;
                    }
 
                    int now = subTree[a][j].second.second;
                    if(now % k == 0) now = 0;
                    ditbl[a][subTree[a][j].first] += now;
                    ditbl[subTree[a][j].first][a] += now;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 42432