#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; struct SegmentTree { using D = lint; using T = struct { D sum, sz; }; static T op(const T& a, const T& b) { return {a.sum + b.sum, a.sz + b.sz}; } static constexpr T e() { return {0, 0}; } using U = struct { D p, q; bool operator==(const auto& r) const { return p == r.p and q == r.q; } }; static void ap(const U& f, T& a) { a.sum = f.p * a.sum + f.q * a.sz; } static void cp(const U& g, U& f) { f.p *= g.p, f.q = g.p * f.q + g.q; } static constexpr U id() { return {1, 0}; } const int n; V t; V u; SegmentTree(int n) : n(n), t(2 * n, e()), u(n, id()) {} T& operator[](int i) { return t[i + n]; } void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); } void push() { for (int i = 1; i < n; ++i) push(i); } void apply(const U& f, int i) { ap(f, t[i]); if (i < n) cp(f, u[i]); } void push(int i) { if (u[i] == id()) return; apply(u[i], 2 * i); apply(u[i], 2 * i + 1); u[i] = id(); } void push(int l, int r) { for (int hl = __lg(l + n), hr = __lg(r - 1 + n); hr > 0; --hl, --hr) { int al = l + n >> hl, ar = r - 1 + n >> hr; if (al < n) push(al); if (ar != al) push(ar); } } T acc(int l, int r) { push(l, r); T resl = e(), resr = e(); for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) resl = op(resl, t[l++]); if (r & 1) resr = op(t[--r], resr); } return op(resl, resr); } T get(int i) { return acc(i, i + 1); } void act(int l, int r, const U& f) { push(l, r); for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) { if (i & 1) apply(f, i++); if (j & 1) apply(f, --j); } l = l + n >> __builtin_ctz(l + n); while (l >>= 1) t[l] = op(t[2 * l], t[2 * l + 1]); r = r + n >> __builtin_ctz(r + n); while (r >>= 1) t[r] = op(t[2 * r], t[2 * r + 1]); } void set(int i, const T& a) { push(i, i + 1); t[i += n] = a; while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]); } }; // 部分木vは[in[v],out[v])に対応 struct HeavyLightDecomposition { const bool edge; const int n; VV<> g; V<> sz, par, in, out, anc, rev; HeavyLightDecomposition(VV<>& g, bool edge, int r = 0) : edge(edge), n(g.size()), g(g), sz(n), par(n), in(n), out(n), anc(n), rev(n) { dfs_sz(r, -1); anc[r] = r; dfs_hl(r); } void dfs_sz(int v, int p) { par[v] = p; for (auto&& w : g[v]) if (w == p) { swap(w, g[v].back()); g[v].pop_back(); break; } sz[v] = 1; for (auto&& w : g[v]) { dfs_sz(w, v); sz[v] += sz[w]; if (sz[w] > sz[g[v][0]]) swap(w, g[v][0]); } } void dfs_hl(int v) { static int t = 0; in[v] = t++; rev[in[v]] = v; for (int w : g[v]) { anc[w] = w == g[v][0] ? anc[v] : w; dfs_hl(w); } out[v] = t; } int lca(int u, int v) const { while (true) { if (in[u] > in[v]) swap(u, v); if (anc[u] == anc[v]) return u; v = par[anc[v]]; } } auto acc(SegmentTree& st, int u, int v) const { auto res = st.e(); while (true) { if (in[u] > in[v]) swap(u, v); if (anc[u] == anc[v]) break; res = st.op(res, st.acc(in[anc[v]], in[v] + 1)); v = par[anc[v]]; } res = st.op(res, st.acc(in[u] + edge, in[v] + 1)); return res; } void act(SegmentTree& st, int u, int v, const SegmentTree::U& f) const { while (true) { if (in[u] > in[v]) swap(u, v); if (anc[u] == anc[v]) break; st.act(in[anc[v]], in[v] + 1, f); v = par[anc[v]]; } st.act(in[u] + edge, in[v] + 1, f); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; VV<> g(n); V<> u(n - 1), v(n - 1), w(n - 1); for (int i = 0; i < n - 1; ++i) { cin >> u[i] >> v[i] >> w[i]; g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } HeavyLightDecomposition hld(g, true); SegmentTree st(n); for (int i = 0; i < n; ++i) st[i] = {0, 1}; st.build(); for (int i = 0; i < n - 1; ++i) { hld.act(st, u[i], v[i], {1, w[i]}); } int q; cin >> q; while (q--) { int tp; cin >> tp; if (tp == 1) { int v, x; cin >> v >> x; st.act(hld.in[v] + 1, hld.out[v], {1, x}); } else { int v; cin >> v; cout << hld.acc(st, 0, v).sum << '\n'; } } }