eolymp
bolt
Try our new interface for solving problems
Problems

Counting Graphs

Counting Graphs

Bessie has a connected, undirected graph G with n vertices labeled 1..n and m edges. G may contain self-loops (edges from nodes back to themselves), but no parallel edges (multiple edges connecting the same endpoints).

Let fG(a, b) be a boolean function that evaluates to true if there exists a path from vertex 1 to vertex a that traverses exactly b edges for each 1an and 0b, and false otherwise. If an edge is traversed multiple times, it is included that many times in the count.

Elsie wants to copy Bessie. In particular, she wants to construct an undirected graph G′ such that fG′(a, b) = fG(a, b) for all a and b.

Your job is to count the number of distinct graphs G′ that Elsie may create, modulo 109 + 7. As with G, G′ may contain self-loops but no parallel edges (meaning that there are 2 ^ ((n2 + n) / 2) distinct graphs on n labeled vertices in total).

Each input contains t test cases that should be solved independently. It is guaranteed that the sum of n2 over all test cases does not exceed 105.

Input

The first line contains t (1t105 / 4), the number of test cases.

The first line of each test case contains the integers n and m (1n102, n1m ≤ (n2 + n) / 2.

The next m lines of each test case each contain two integers x and y (1xyn), denoting that there exists an edge between x and y in G.

Consecutive test cases are separated by newlines for readability.

Output

For each test case, the number of distinct G′ modulo 109 + 7 on a new line.

Example

In the first test case, G′ could equal G or one of the two following graphs:

5 4
1 2
1 4
3 4
3 5
5 5
1 2
2 3
1 4
3 4
3 5
Time limit 1 second
Memory limit 128 MiB
Input example #1
1

5 4
1 2
2 3
1 4
3 5
Output example #1
3
Source 2021 USACO February, Platinum