#include namespace { #include using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; ll op(ll x, ll y) { return x ^ y; } ll e() { return 0; } bool compositoin(bool f, bool g) { return f && g; } bool id() { return true; } ll mapping(bool f, ll x) { return f * x; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector>> g(n); rep(i, n - 1) { int l, r; ll a; cin >> l >> r >> a; l--; r--; g[l].emplace_back(r, a); g[r].emplace_back(l, a); } VI in_time(n), out_time(n); VL a_par(n); int time = 0; auto dfs = [&](auto self, int u, int p) -> void { in_time[u] = time; time++; for(auto [v, a] : g[u]) { if (v != p) { a_par[time] = a; self(self, v, u); } } out_time[u] = time; }; dfs(dfs, 0, -1); lazy_segtree seg(a_par); int q; cin >> q; rep(_, q) { int t, x; cin >> t >> x; x--; if (t == 1) { seg.apply(in_time[x], out_time[x], false); } else { int ans = seg.prod(in_time[x] + 1, out_time[x]); cout << ans << '\n'; } } }