Sum of Distances

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Bessie has a collection of connected, undirected graphs G_1,G_2,,G_KG\_1,G\_2,\ldots,G\_K (2K51042\le K\le 5\cdot 10^4). For each 1iK1\le i\le K, G_iG\_i has exactly N_iN\_i (N_i2N\_i\ge 2) vertices labeled 1N_i1\ldots N\_i and M_iM\_i (M_iN_i1M\_i\ge N\_i-1) edges. Each G_iG\_i may contain self-loops, but not multiple edges between the same pair of vertices.

Now Elsie creates a new undirected graph GG with N_1N_2N_KN\_1\cdot N\_2\cdots N\_K vertices, each labeled by a KK-tuple (j_1,j_2,,j_K)(j\_1,j\_2,\ldots,j\_K) where 1j_iN_i1\le j\_i\le N\_i. In GG, two vertices (j_1,j_2,,j_K)(j\_1,j\_2,\ldots,j\_K) and (k_1,k_2,,k_K)(k\_1,k\_2,\ldots,k\_K) are connected by an edge if for all 1iK1\le i\le K, j_ij\_i and k_ik\_i are connected by an edge in G_iG\_i.

Define the distance between two vertices in GG 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)(1,1,\ldots,1) and every vertex in the same component as it in GG, modulo 109+710^9+7.

입력

The first line contains KK, the number of graphs.

Each graph description starts with N_iN\_i and M_iM\_i on a single line, followed by M_iM\_i edges.

Consecutive graphs are separated by newlines for readability. It is guaranteed that N_i105\sum N\_i\le 10^5 and M_i2105\sum M\_i\le 2\cdot 10^5.

출력

The sum of the distances between vertex (1,1,,1)(1,1,\ldots,1) and every vertex that is reachable from it, modulo 109+710^9+7.