Bessie has a collection of connected, undirected graphs G_1,G_2,…,G_K (2≤K≤5⋅104). For each 1≤i≤K, G_i has exactly N_i (N_i≥2) vertices labeled 1…N_i and M_i (M_i≥N_i−1) edges. Each G_i may contain self-loops, but not multiple edges between the same pair of vertices.
Now Elsie creates a new undirected graph G with N_1⋅N_2⋯N_K vertices, each labeled by a K-tuple (j_1,j_2,…,j_K) where 1≤j_i≤N_i. In G, two vertices (j_1,j_2,…,j_K) and (k_1,k_2,…,k_K) are connected by an edge if for all 1≤i≤K, j_i and k_i are connected by an edge in G_i.
Define the distance between two vertices in G that lie in the same connected component to be the minimum number of edges along a path from one vertex to the other. Compute the sum of the distances between vertex (1,1,…,1) and every vertex in the same component as it in G, modulo 109+7.
The first line contains K, the number of graphs.
Each graph description starts with N_i and M_i on a single line, followed by M_i edges.
Consecutive graphs are separated by newlines for readability. It is guaranteed that ∑N_i≤105 and ∑M_i≤2⋅105.
The sum of the distances between vertex (1,1,…,1) and every vertex that is reachable from it, modulo 109+7.