Fantasia

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

문제

Professor Zhang has an undirected graph GG with nn vertices and mm edges. Each vertex has an integer weight w_iw\_i. Let G_iG\_i be the graph obtained by deleting the ii-th vertex from graph GG. Professor Zhang wants to find the weights of G_1,G_2,,G_nG\_1, G\_2, \ldots, G\_n.

The weight of a graph GG is defined as follows:

  • If GG is connected, then the weight of GG is the product of the weight of each vertex in GG.
  • Otherwise, the weight of GG is the sum of the weights of all the connected components of GG.

A connected component HH of an undirected graph GG is a subgraph in which any two vertices are connected by a path, and no other vertex in GG is connected to any vertex from HH by a path.

입력

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 two integers nn and mm (2n1052 \le n \le 10^5, 1m21051 \le m \le 2 \cdot 10^5): the number of vertices and the number of edges.

The second line contains nn integers w_1,w_2,,w_nw\_1, w\_2, \ldots, w\_n (1w_i1091 \le w\_i \le 10^9) denoting the weight of each vertex.

Each of the next mm lines contains two integers x_ix\_i and y_iy\_i (1x_i,y_in1 \le x\_i, y\_i \le n, x_iy_ix\_i \ne y\_i) denoting an undirected edge.

There are at most 10001000 test cases, the sum of nn in all the test cases is at most 1.51061.5 \cdot 10^6, and the sum of mm in all the test cases is also at most 1.51061.5 \cdot 10^6.

출력

For each test case, output the integer S=(_i=1niz_i)S = (\sum\limits\_{i = 1}^{n}{i \cdot z\_i}) modulo 109+710^9 + 7, where z_iz\_i is the weight of G_iG\_i.