#P7827. A Very Easy Graph Problem

A Very Easy Graph Problem

A Very Easy Graph Problem

Problem Description

An undirected connected graph has nn nodes and mm edges, The ii-th edge’s length is 2i2^i. Each node ii has a value aia_i, which is either 00 or 11. You need to calculate:

$$\sum_{i=1}^{n}\sum_{j=1}^{n}d(i,j)\times [a_i=1\wedge a_j=0] $$

d(i,j)d(i,j) indicates the shortest distance between ii and jj. [ ][\ ] is the Iverson bracket. \wedge indicates AND\texttt{AND}. Because the answer may be too large, please output the answer modulo 109+710^9 + 7.

Input

The first line contains one integer TT(1T81\le T \le 8),indicating the number of test cases. The second line contains two ingeters n,mn,m(1n105,1m2×1051\le n\le 10^5,1\le m\le 2\times 10^5). The third line contains nn positive integers a1,a2,...,an(ai=0a_1,a_2,...,a_n(a_i = 0 or 11) —— the value of the nodes. The following mm lines contain two ingeters u,v(1u,vn)u,v(1 \le u,v \le n), and the ii-th line represents the i-th undirected edge’s length is 2i2^i, between node uu and vv. The sum of n,mn,m is no more than 2×1052\times 10^5.

Output

Print a single integer—— the value of the answer modulo 109+710^9+7.

Sample Input

1
3 2
0 1 0
3 1
3 2

Sample Output

10

Source

2020 Multi-University Training Contest 6