This page is still under construction.

Parts of this page are still being built. What you see may change.

Fantasia

Time limit5sMemory limit64 MB

Summary
For each vertex i, compute the weight of the graph with i removed, where a connected graph weighs the product of its vertex weights and a disconnected one weighs the sum of its components.
Level

Medium7 of 10

Topics
Graph, DFS, Brute force, Math
Solved
No attempts yet

Problem

Professor Zhang has an undirected graph GG with nn vertices and mm edges. Each vertex has an integer weight wiw_i. Let GiG_i be the graph obtained by deleting the ii-th vertex from graph GG. Professor Zhang wants to find the weights of G1,G2,…,GnG_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.

Input

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 (2≤n≤1052 \le n \le 10^5, 1≤m≤2⋅1051 \le m \le 2 \cdot 10^5): the number of vertices and the number of edges.

The second line contains nn integers w1,w2,…,wnw_1, w_2, \ldots, w_n (1≤wi≤1091 \le w_i \le 10^9) denoting the weight of each vertex.

Each of the next mm lines contains two integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i, y_i \le n, xi≠yix_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.5⋅1061.5 \cdot 10^6, and the sum of mm in all the test cases is also at most 1.5⋅1061.5 \cdot 10^6.

Output

For each test case, output the integer S=(∑i=1ni⋅zi)S = (\sum\limits_{i = 1}^{n}{i \cdot z_i}) modulo 109+710^9 + 7, where ziz_i is the weight of GiG_i.

Examples1

  1. Example 1

    Input
    1
    3 2
    1 2 3
    1 2
    2 3
    
    Expected output
    20