题目
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int maxn = 1e6 + 5, inf = 1e9 + 5, maxm = 1e6 + 5, mod = 1e9 + 7;
int a[maxn], b[maxn], c[maxn];
int n, m;
map<int, int> mp;
// int suf[maxn], pre[maxn];
// bool vis[maxn];
int tot, q;
int tim[maxn];
vector<int> G[maxn];
struct Data{
int tim, val;//时间,权值
};
vector<Data> dat[maxn];
int t[maxn];//t[i]表示在[i - lowbit(i) + 1, i]的时间段上生成的结点都(注意是都!)能加到的权值
int ans[maxn];
int lowbit(int x){
return x & -x;
}
void insert(int x, int k){//在[1, x]时间段上的结点都加上k
for(int i = x; i >= 1; i -= lowbit(i)){
t[i] += k;
}
}
int ask(int x){//询问在x时间生成的结点能加到的权值和
int res = 0;
for(int i = x; i <= q; i += lowbit(i)){
res += t[i];
}
return res;
}
void dfs(int u){
for(auto x : dat[u]){
insert(x.tim, x.val);
}
ans[u] = ask(tim[u]);
for(auto v : G[u]){
dfs(v);
}
for(auto x : dat[u]){//回溯要减去该结点的影响
insert(x.tim, -x.val);
}
}
void solve()
{
// cin >> n >> m;
// for(int i = 1; i <= n; i++){
// cin >> a[i];
// }
// int q;
cin >> q;
for(int i = 1; i <= q; i++){
G[i].clear();
dat[i].clear();
t[i] = 0;
}
tot = 1;
tim[1] = 1;
for(int i = 1; i <= q; i++){
int op, p, x;
cin >> op;
if(op == 1){
cin >> p;
tot++;
G[p].pb(tot);
tim[tot] = i;
}
else{
cin >> p >> x;
dat[p].pb({i, x});
}
}
dfs(1);
for(int i = 1; i <= tot; i++){
cout << ans[i] << " \n"[i == tot];
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}