#P17419. [ICPC 2018 Xuzhou R] Rikka with Line Graphs

[ICPC 2018 Xuzhou R] Rikka with Line Graphs

Problem Description

Several years of ACM-ICPC experience enables Rikka, as a student at Keping University, to catch the tide of the algorithm development.

Over the courses for this semester, Rikka made a deep study of line graphs. In the mathematical discipline of graph theory, the line graph of a simple undirected graph GG is another simple undirected graph L(G)L(G) that represents the adjacency between every two edges in GG. Precisely speaking, for an undirected graph GG without loops or multiple edges, its line graph L(G)L(G) is a graph such that

  • each vertex of L(G)L(G) represents an edge of GG; and
  • two vertices of L(G)L(G) are adjacent if and only if their corresponding edges share a common endpoint in GG.

:::align{center} :::

Given a simple undirected graph GG, Rikka's study aims to count the number of vertices in its line graph. Now she decides to show you some critical results of her early study, concerning the number of vertices in the line graph of GG, L(G)L(G), the line graph of the line graph of GG, L2(G)L^2(G) (i.e. L(L(G))L(L(G))), and so forth, denoted by ∣V(L(G))∣|V(L(G))|, ∣V(L2(G))∣|V(L^2(G))|, ⋯\cdots.

By the definition of an undirected graph with nn vertices and mm edges, we know that

$$|V(L(G))| = \sum_e 1 = m = \frac{1}{2} \sum_u d_1(u),$$

where d1(u)d_1(u) represents the degree of vertex uu in GG.

Once we know how to count, for any edge ee in GG, the number of edges which share a common endpoint with ee, or equally speaking the degree of ee in L(G)L(G), which is denoted by d1′(e)d_1^{'}(e), we have

$$|V(L^2(G))| = \frac{1}{2} \sum_e d_1^{'}(e) = \frac{1}{2} \sum_{e = (u, v)} (d_1(u) - 1 + d_1(v) - 1) = \frac{1}{2} \sum_{u} d_1(u) (d_1(u) - 1).$$

A similar easy analysis can help us to calculate ∣V(L3(G))∣|V(L^3(G))|, and an excellent result in Rikka's known work, which was published in the 2018 JheZiang Olympiad in Informatics, reveals the number of vertices in L4(G)L^4(G) as

$$\begin{aligned}|V(L^4(G))| = \frac{1}{2} \sum_{u} &(2 d_1^2(u) - 13 d_1(u) + 21 + 4 d_2(u)) d_1(u) (d_1(u) - 1) \\ &-13 (d_1(u) - 1) d_2(u) + (d_1(u) - 2) d_{2, 2}(u) + d_2^2(u),\end{aligned}$$

where d2(u)d_2(u) is the summation of degrees of all adjacent vertices of uu in GG, and when considering the degrees squared of all adjacent vertices of uu, d2,2(u)d_{2, 2}(u) is the summation of them all.

Based on the equation L5(G)=L4(L(G))L^5(G) = L^4(L(G)), her newest work made a further development. She extrapolates from the result about L4(G)L^4(G) a linear computable method to calculate the number of vertices in L5(G)L^5(G) in time complexity O(n+m)O(n + m). Rikka pointed out that the data about vertices required in the summation form of ∣V(L4(G))∣|V(L^4(G))| imply new data about edges with similar definitions. Actually, the relationship between d1d_1 and d1′d_1^{'} is the easiest correspondence. A harder one is described as the one between d2d_2 and d2′d_2^{'}. Luckily, we can calculate all these new data which we need about the edges in linear time. Thus an attempt replacing the summation of vertices by a summation of edges provides a strict formula for the number of vertices in L5(G)L^5(G).

Now you must try to go with the current of the times. In this problem, for an undirected simple graph GG, you are asked to calculate the number of vertices in L6(G)L^6(G) and output the number modulo (109+7)(10^9 + 7).

Input Format

The input contains several test cases, and the first line contains a single integer TT (1≤T≤101 \le T \le 10), the number of test cases.

For each test case, the first line contains two integers nn (1≤n≤1051 \le n \le 10^5) and mm (0≤m≤2×1050 \le m \le 2 \times 10^5), the number of vertices and edges in the given simple undirected graph GG.

Then mm lines follow, describing all edges of the graph. Each line of them contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v), representing an edge between the uu-th vertex and the vv-th vertex.

The input guarantees that the given graph for each test case contains no loops or multiple edges.

Output Format

For each test case, output a single line with a single integer, the remainder of the number of vertices in L6(G)L^6(G) divided by (109+7)(10^9 + 7).

2
4 4
1 2
2 3
3 1
4 1
4 4
1 2
2 3
3 4
4 1
396
4