#P7831. Expectation
Expectation
Expectation
Problem Description
You are given an undirected graph consisting of vertices with weighted edges. We define the weight of a spanning tree as the bitwise AND of all edges' weight in spanning tree. Now select a spanning tree randomly, you should calculate the expected value of the weight of this spanning tree. You are required to print the result mod . , print mod where is the irreducible fraction representation of the result, where denotes the multiplicative inverse of modulo .
Input
The first line is an integer , the number of test cases. For each test case, there are two space-separated integers and in the first line, the number of nodes and the number of edges. Then follows lines, each contains three integers $u, v, w(1 \leq u, v, \leq n, 1 \leq w \leq 10^{9}, u \neq v)$, space separated, denoting an weight edge between and has weight .
Output
For each test case, output a single line with a single integer, denoting the answer.
Sample Input
1
3 3
1 2 1
1 3 1
2 3 1
Sample Output
1
Source
2020 Multi-University Training Contest 6