#P7790. Little W and Contest

Little W and Contest

Little W and Contest

Problem Description

There are nn members in our ACM club. Little W wants to select three persons from our club to form a new team taking part in provincial ACM contests, as it is known by all of us that any ACM contest requires a normal team to have three members. Little W has divided our club members into two role groups. The first group contains only readers who dedicate themselves to reading problems during contests, though sometimes they may also prepare drinking and food for the team. For the sake of measurement, we define the power of a reader as 11. The second part contains only coders who code and test programs all the time, and similarly, we define the power of a coder as 22. Little W thinks it will be a tremendous disaster when a team has two readers because in that case, the total power of this team is less than 55 and thus it has a high risk to fail the contest. To avoid that, Little W thinks a new team must have at least two coders. Additionally, Little W defines the relationship between club members with transitivity. That is, for every three members AA, BB, and CC, if AA is familiar with BB, and BB is familiar with CC, then AA will be familiar with CC through BB instantly. Based on the definition, it is forbidden for the team to have any two members familiar with each other. At first, no member of our club is familiar with any other, and then Little W will repeatedly make an introduction between two members who are currently strangers to each other until each member is familiar with all the others. During this process, there will be exactly (n1)(n - 1) introductions. Now, for i=1,2,,ni = 1, 2, \ldots, n, Little W wants you to count the combinations of three club members that can form a new team after the first (i1)(i - 1) introductions have been made. However, the numbers of combinations may be quite gigantic, so you just need to report each number in modulo (109+7)(10^9 + 7).

Input

There are several test cases. The first line contains an integer TT (1T101 \leq T \leq 10), denoting the number of test cases. Then follow all the test cases. For each test case, the first line contains an integer nn (1n105)(1 \leq n \leq 10^5), denoting the number of members in this club. The second line contains nn integers consisting of only 11 and 22, where the ii-th integer represents the power of the ii-th member. The next (n1)(n - 1) lines describe all introductions in chronological order of occurrence, where each line contains two integers uu and vv (1u,vn,uv)(1 \leq u, v \leq n, u \neq v), representing an introduction between the uu-th member and the vv-th member, who are currently strangers to each other. It is guaranteed that the sum of nn is no larger than 10610^6.

Output

For each test case, output nn lines, where the ii-th line contains an integer, denoting the number of combinations of three club members, in modulo (109+7)(10^9 + 7), that can form a new team after the first (i1)(i - 1) introductions have been made.

Sample Input

1
5
2 2 2 1 1
4 5
1 4
2 1
3 2

Sample Output

7
7
3
0
0

Source

2020 Multi-University Training Contest 3