#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Segtree {
    int n;
    ll m;
    vector<ll> dat, dam;
    Segtree(){};
    void build(int n_, int m_) {
        n = 1;
        m = m_;
        while (n < n_) {
            n <<= 1;
        }
        dat.resize(2 * n);
        dam.resize(2 * n);
    }
    void add(int k, ll x) {
        k += n;
        dat[k] += x;
        if (dat[k] % m == 0) {
            dam[k] = dat[k];
        } else {
            dam[k] = 0;
        }
        k >>= 1;
        while (k > 0) {
            dat[k] = dat[k << 1] + dat[k << 1 | 1];
            dam[k] = dam[k << 1] + dam[k << 1 | 1];
            k >>= 1;
        }
    }
    ll get(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a) {
            return 0;
        }
        if (a <= l && r <= b) {
            return dat[k] - dam[k];
        }
        return get(a, b, 2 * k, l, (l + r) / 2) +
               get(a, b, 2 * k + 1, (l + r) / 2, r);
    }
    ll get(int a, int b) { return get(a, b, 1, 0, n); }
};
using P = pair<int, int>;
map<P, ll> mp;
struct HLD {
    int n, pos;
    vector<vector<int>> G;
    vector<int> nid, hrt, nxt, siz, par;
    vector<ll> laz;
    Segtree seg;
    HLD(int n)
        : n(n), G(n), pos(0), nid(n, -1), hrt(n, -1), nxt(n, -1), siz(n, 1),
          par(n, -1), laz(n) {}
    void add_edge(int u, int v) {
        G[u].push_back(v);
        G[v].push_back(u);
    }
    void build(int m) {
        seg.build(n, m);
        dfs(0);
        bfs();
    }
    void dfs(int i) {
        int ma = 0;
        for (auto &e : G[i]) {
            if (e == par[i]) {
                continue;
            }
            par[e] = i;
            dfs(e);
            siz[i] += siz[e];
            if (ma < siz[e]) {
                ma = siz[e];
                nxt[i] = e;
            }
        }
    }
    void bfs() {
        queue<int> q;
        q.push(0);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            int i = v;
            while (i != -1) {
                nid[i] = pos++;
                hrt[i] = v;
                for (auto &e : G[i]) {
                    if (e != par[i] && e != nxt[i]) {
                        q.push(e);
                    }
                }
                i = nxt[i];
            }
        }
    }
    ll get(int u, int v) {
        ll res = 0;
        while (1) {
            if (nid[u] > nid[v]) {
                swap(u, v);
            }
            if (hrt[u] != hrt[v]) {
                res += seg.get(nid[hrt[v]], nid[v]);
                // cout<<hrt[v]<<" "<<v<<" "<<seg.get(nid[hrt[v]],nid[v])<<endl;
                if (par[hrt[v]] != -1) {
                    ll t = mp[P(par[hrt[v]], hrt[v])] + laz[par[hrt[v]]];
                    // cout<<hrt[v]<<" "<<v<<" "<<t<<endl;
                    if (t % seg.m > 0) {
                        res += t;
                    }
                }
                v = par[hrt[v]];
            } else {
                if (u != v) {
                    res += seg.get(nid[u], nid[v]);
                    // cout<<u<<" "<<v<<" "<<seg.get(nid[u],nid[v])<<endl;
                }
                break;
            }
        }
        return res;
    }
    void add(int u, ll x) {
        seg.add(nid[u], x);
        if (par[u] != -1 && u != hrt[u]) {
            seg.add(nid[par[u]], x);
        } else if (par[u] != -1) {
            mp[P(par[u], u)] += x;
        }
        laz[u] += x;
    }
};
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n), c(n);
    HLD g(n);
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i] >> c[i];
        g.add_edge(a[i], b[i]);
    }
    g.build(k);
    for (int i = 0; i < n - 1; i++) {
        int u = g.nid[a[i]], v = g.nid[b[i]];
        if (u > v) {
            swap(a[i], b[i]);
            swap(u, v);
        }
        if (g.nxt[a[i]] == b[i]) {
            g.seg.add(u, c[i]);
        } else {
            mp[P(a[i], b[i])] = c[i];
        }
    }
    int q;
    cin >> q;
    while (q--) {
        string s;
        ll a, b;
        cin >> s >> a >> b;
        if (s == "add") {
            g.add(a, b);
        } else if (s == "send") {
            cout << g.get(a, b) << endl;
        }
    }
}



Measured memory_bytes: 22740