#SL2310A. Almost Acyclic
Almost Acyclic
Almost Acyclic
We call a connected undirected graph almost-acyclic, if the graph has no cycles, or all the simple cycles in it share at least one common point.
You are given a complete undirected graph with vertices. Each edge has a weight . Calculate ( is if is almost-acyclic, or otherwise):
$$\sum_{E'\subseteq E,\: G'=(V,E')} f(G') \prod_{(i,j) \in E'} w_{i,j} \bmod 10^9+7 $$Input
The first line contains a single integer , denoting the number of test cases.
For each test case, the first line contains an integer .
The next lines each contains integers. The -th number in the -th line denotes .
It is guaranteed that , .
It is guaranteed that for each , there is at most one test case satisfying .
Output
For each test case, output one line with an integer denoting the answer.
Example
2
3
0 1 2
1 0 1
2 1 0
5
0 1 0 1 1
1 0 1 1 1
0 1 0 1 0
1 1 1 0 1
1 1 0 1 0
7
120