A. Yet Another Colored Tree Problem

Time limit: 1s
Memory limit: 256MB
Input:
Output:

You are given a tree with nn nodes. Each node has a color between 11 and kk.

For each color ii from 11 to kk, print the number of simple paths that contain at least one node with color ii.

A simple path is a sequence of edges (u1,u2),(u2,u3),,(uk1,uk)(u_1,u_2),(u_2,u_3),\ldots,(u_{k-1},u_k) for which all uiu_i are pairwise distinct. Two paths are considered different if their corresponding sequences of edges are distinct.

Input

Each test contains multiple testcases. The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains two integers nn and kk (1kn31051 \le k \le n \le 3 \cdot 10^5) — the number of nodes and colors, respectively.

The second line contains nn integers c1,c2,,cnc_1,c_2,\ldots,c_n (1cik1 \le c_i \le k) — the colors of the nn nodes.

Each of the next n1n-1 lines contain two integers uiu_i and viv_i (1ui,vin1 \le u_i,v_i \le n, uiviu_i \neq v_i), meaning that an undirected edge exists between nodes uiu_i and viv_i.

It is guaranteed that the given graph is a tree (an undirected connected graph without cycles).

It is also guaranteed that the sum of nn across all testcases does not exceed 31053 \cdot 10^5.

Output

For each testcase, print kk integers, the number of simple paths that contain at least one node with color ii, for every color ii from 11 to kk.

Example

stdin

4
3 3
1 1 3
1 2
1 3
1 1
1
5 3
1 2 3 2 1
1 2
1 3
3 4
3 5
8 7
1 1 2 3 5 6 7 2
1 2
1 3
1 4
2 5
2 6
3 7
5 8

stdout

8 0 5
1
20 16 19
54 38 15 0 27 15 15

Note

Explanation of the first testcase:

There are 88 simple paths that contain at least one node with color 11:

  • [1][1]
  • [2][2]
  • [12][1 \rightarrow 2]
  • [21][2 \rightarrow 1]
  • [13][1 \rightarrow 3]
  • [31][3 \rightarrow 1]
  • [213][2 \rightarrow 1 \rightarrow 3]
  • [312][3 \rightarrow 1 \rightarrow 2]

Since there are no nodes with color 22, there are no paths that contain a node with color 22.

Finally, there are 55 simple paths that contain at least one node with color 33:

  • [3][3]
  • [31][3 \rightarrow 1]
  • [13][1 \rightarrow 3]
  • [312][3 \rightarrow 1 \rightarrow 2]
  • [213][2 \rightarrow 1 \rightarrow 3]

In the second testcase, the only path ([1][1]) contains one node with color 11.

Log in or sign up to be able to send submissions!