Under construction

Still being built. Things may change

Call It What You Want

Time limit1sMemory limit64 MB

Summary
Given a connected graph with at most four edges beyond a spanning tree, find the length of the longest simple path.
Level

Medium7 of 10

Topics
Graph, Tree, Dynamic programming
Solved
No attempts yet

Problem

Professor Zhang has heard that the longest path problem cannot be solved in polynomial time for arbitrary graphs unless P = NP. Now, Professor Zhang would like to solve this problem in polynomial time in some graphs.

The longest path problem is the problem of finding a simple path of maximum length in a given graph. A path is called simple if it does not have any repeated vertices. The length of a path is the number of edges in this path.

Input

There are multiple test cases. The first line of input contains an integer TT (about 350350) indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (3≤n≤1043 \le n \le 10^4, n≤m≤n+4n \le m \le n + 4): the number of vertices and the number of edges.

Each of the following mm lines contains two integers aia_i and bib_i which denotes an edge between vertices aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i).

It is guaranteed that the graph is connected and does not contain multiple edges.

The total size of the input is at most 44 MiB.

Output

For each test case, output an integer denoting the length of the longest path.

Examples1

  1. Example 1

    Input
    3
    5 5
    1 2
    2 3
    3 4
    4 5
    5 1
    7 7
    1 2
    2 3
    3 4
    4 5
    5 1
    5 6
    4 7
    7 10
    1 2
    2 3
    3 4
    4 5
    1 5
    2 5
    3 5
    1 6
    5 6
    4 7
    
    Expected output
    4
    6
    6