Monster Hunter

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

There is a rooted tree with nn vertices and the root vertex is 11. In each vertex, there is a monster. The hit points of the monster in the ii-th vertex is hp_ihp\_i.

Kotori would like to kill all the monsters. The monster in the ii-th vertex could be killed if the monster in the direct parent of the ii-th vertex has been killed. The power needed to kill the ii-th monster is the sum of hp_ihp\_i and the hit points of all other living monsters who lives in a vertex jj whose direct parent is ii. Formally, the power equals to hp_i+_the monster in vertex j is alive and i is the direct parent of jhp_jhp\_i + \sum\_{\begin{array}{c}\text{the monster in vertex } j \text{ is alive} \\\ \text{and } i \text{ is the direct parent of } j \end{array}} hp\_j

In addition, Kotori can use some magic spells. If she uses one magic spell, she can kill any monster using 00 power without any restriction. That is, she can choose a monster even if the monster in the direct parent is alive.

For each m=0,1,2,,nm=0,1,2,\cdots,n, Kotori would like to know, respectively, the minimum total power needed to kill all the monsters if she can use mm magic spells.

입력

There are multiple test cases. The first line of input contains an integer TT indicating the number of test cases. For each test case:

The first line contains an integer nn (2n2×1032 \le n \le 2 \times 10^3), indicating the number of vertices.

The second line contains (n1)(n-1) integers p_2,p_3,,p_np\_2,p\_3,\cdots,p\_n (1p_i<i1 \le p\_i < i), where p_ip\_i means the direct parent of vertex ii.

The third line contains nn integers hp_1,hp_2,,hp_nhp\_1,hp\_2,\cdots,hp\_n (1hp_i1091 \le hp\_i \le 10^9) indicating the hit points of each monster.

It's guaranteed that the sum of nn of all test cases will not exceed 2×1032 \times 10^3.

출력

For each test case output one line containing (n+1)(n+1) integers a_0,a_1,,a_na\_0, a\_1, \cdots, a\_n separated by a space, where a_ma\_m indicates the minimum total power needed to kill all the monsters if Kotori can use mm magic spells.