#648. Islands and Bridges

Islands and Bridges

Description

Given a map of islands and bridges that connect these islands, a Hamilton path, as we all know, is a path along the bridges such that it visits each island exactly once. On our map, there is also a positive integer value associated with each island. We call a Hamilton path the best triangular Hamilton path if it maximizes the value described below.

Suppose there are n islands. The value of a Hamilton path C1,C2,...,CnC_1,C_2,...,C_n is calculated as the sum of three parts. Let ViV_i be the value for the island CiC_i. As the first part, we sum over all the ViV_i values for each island in the path. For the second part, for each edge Ci,Ci+1C_i,C_{i+1} in the path, we add the product Vi×Vi+1V_i\times V_i+1. And for the third part, whenever three consecutive islands Ci,Ci+1,Ci+2C_i,C_{i+1},C_{i+2} in the path forms a triangle in the map, i.e. there is a bridge between CiC_i and Ci+2C_{i+2}, we add the product Vi×Vi+1×Vi+2V_i\times V_{i+1}\times V_{i+2}.

Most likely but not necessarily, the best triangular Hamilton path you are going to find contains many triangles. It is quite possible that there might be more than one best triangular Hamilton paths; your second task is to find the number of such paths.

Input

The input file starts with a number QQ on the first line, which is the number of test cases. Each test case starts with a line with two integers nn and mm, which are the number of islands and the number of bridges in the map, respectively. The next line contains nn positive integers, the ii-th number being the ViV_i value of island ii. Each value is no more than 100100. The following mm lines are in the form x y, which indicates there is aa (two way) bridge between island xx and island yy. Islands are numbered from 11 to nn. You may assume there will be no more than 1313 islands.

Output

For each test case, output a line with two numbers, separated by a space. The first number is the maximum value of a best triangular Hamilton path; the second number should be the number of different best triangular Hamilton paths. If the test case does not contain a Hamilton path, the output must be 0 0.

Note: A path may be written down in the reversed order. We still think it is the same path.

2

3 3
2 2 2
1 2
2 3
3 1

4 6
1 2 3 4
1 2
1 3
1 4
2 3
2 4
3 4
22 3
69 1

Constraints

1Q201 \le Q \le 20

1n131 \le n \le 13