#P9852. Counting Stars

Counting Stars

Counting Stars

Problem Description

We define a kk-star graph (k2)(k\ge 2) is a connected undirected graph with k+1k+1 nodes and kk edges satisfies that all the kk edges are connected to a common node (and it's easy to show that this node is unique), and we call this node as the center of the star graph, and the other nodes are the leaves of the star graph. Now you are given a simple undirected graph with nn nodes and mm edges. Your task is to calculate how many kk-star graphs are there in the given graph for all the integers k[2,n1]k \in [2,n-1] . Specifically, the problem can be described as follows: How many ways are there to choose a node cc and a set of kk nodes {l1,l2,,lk}\{l_1,l_2,\dots,l_k\} in the given graph, satisfies that there exists edges connected cc and each lil_i for all i[1,k]i\in [1,k] in the given graph. Two star graphs are considered different if the center node cc is different or the set of leaves {l1,l2,,lk}\{l_1,l_2,\dots,l_k\} is different. Let cntkcnt_k represent the number of kk-star graphs in the given graph module 109+710^9+7 . You only need to print the bitwise XOR sum of all the cntkcnt_k (i.e. cnt2cnt3cntn1cnt_2\oplus cnt_3\oplus\cdots\oplus cnt_{n-1} ,where \oplus represents bitwise XOR).

Input

The first line of the input contains an integer T (1T5)T\ (1\le T\le 5), indicating the number of the test cases. For each test case: The first line contains two integers n,m (3n106,1m106)n,m\ (3\le n\le 10^6, 1\le m\le 10^6), indicating the number of nodes and edges in the given graph. Then the following mm lines, each line contains two integers u,v (1u,vn,uv)u,v\ (1\le u,v\le n, u\not =v) , indicating an edge in the given graph. It's guaranteed that the graph is simple.

Output

For each test case: print one line contains a single integer, indicating the bitwise XOR sum of all the cntkcnt_k.

Sample Input

2
3 2
1 2
2 3
4 6
1 2
1 3
1 4
2 3
2 4
3 4

Sample Output

1
8

Hint

For the second sample, there are twelve 22-star graphs and four 33-star graphs, so the answer is 124=812\oplus 4 =8. Note that the input scale is very large.

Source

2023“钉耙编程”中国大学生算法设计超级联赛(5)