Under construction

Still being built. Things may change

Counting Graphs

Time limit1sMemory limit512 MB

Summary
Given a connected undirected graph, count the graphs whose walk lengths from vertex 1 to every vertex match the original, modulo 1000000007.
Level

Hard9 of 10

Topics
Graph, BFS, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

Bessie has a connected, undirected graph GG with NN vertices labeled 11 to NN and MM edges. GG may contain self-loops (edges from a vertex back to itself), but no parallel edges (multiple edges between the same pair of endpoints).

Let fG(a,b)f_G(a,b) be a boolean function that is true if there is a path from vertex 11 to vertex aa that uses exactly bb edges, for every 1≤a≤N1 \le a \le N and 0≤b0 \le b. Otherwise it is false. If an edge is traversed several times, it is counted once for each traversal.

Elsie wants to copy Bessie. Specifically, she wants to build an undirected graph G′G' such that fG′(a,b)=fG(a,b)f_{G'}(a,b) = f_G(a,b) for all aa and bb.

Count the distinct graphs G′G' that Elsie can build, modulo 109+710^9+7. Like GG, G′G' may contain self-loops but no parallel edges. There are 2N2+N22^{\frac{N^2+N}{2}} distinct graphs on NN labeled vertices in total.

Input

The first line contains TT, the number of test cases (1≤T≤10541 \le T \le \frac{10^5}{4}).

Each test case starts with a line containing NN and MM (2≤N≤1022 \le N \le 10^2, N−1≤M≤N2+N2N-1 \le M \le \frac{N^2+N}{2}). The next MM lines each contain two integers xx and yy (1≤x≤y≤N1 \le x \le y \le N), meaning that GG has an edge between xx and yy.

Test cases are separated by blank lines for readability. The sum of N2N^2 over all test cases does not exceed 10510^5.

Output

For each test case, print the number of distinct G′G' modulo 109+710^9+7 on its own line.

Examples2

  1. Example 1

    Input
    1
    
    5 4
    1 2
    2 3
    1 4
    3 5
    
    Expected output
    3
    
  2. Example 2

    Input
    7
    
    4 6
    1 2
    2 3
    3 4
    1 3
    2 4
    1 4
    
    5 5
    1 2
    2 3
    3 4
    4 5
    1 5
    
    5 7
    1 2
    1 3
    1 5
    2 4
    3 3
    3 4
    4 5
    
    6 6
    1 2
    2 3
    3 4
    4 5
    5 6
    6 6
    
    6 7
    1 2
    2 3
    1 3
    1 4
    4 5
    5 6
    1 6
    
    10 10
    1 1
    1 2
    1 3
    1 4
    1 5
    1 6
    1 7
    1 8
    1 9
    1 10
    
    22 28
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    1 7
    1 8
    3 9
    8 10
    10 11
    10 12
    10 13
    10 14
    11 15
    12 16
    13 17
    14 18
    9 15
    9 16
    9 17
    9 18
    15 19
    19 20
    15 20
    16 21
    21 22
    16 22
    
    Expected output
    45
    35
    11
    1
    15
    371842544
    256838540