Under construction

Still being built. Things may change

Jellyfish

Time limit2sMemory limit512 MB

Summary
Given a connected graph with n vertices and n edges, find the largest set S where every subset T of S can be joined by a connected subgraph that avoids the other vertices of S.
Level

Hard8 of 10

Topics
Graph, Tree, Dynamic programming, DFS
Solved
No attempts yet

Problem

Everyone knows that at Jagiellonian University we love plants a lot. We created hundreds of problems about trees, forests and even cacti. Unfortunately, problems about animals are not that popular. Today we want to prove that we love animals as well.

A graph is a jellyfish if it is a simple connected undirected graph with the same number of vertices and edges. You are given a jellyfish JJ with nn vertices. For a subset of vertices S⊆JS \subseteq J, call SS an awesome subset if for every T⊆ST \subseteq S there exists a connected subgraph of the jellyfish that contains every vertex of TT and no other vertex of SS.

What is the maximum possible size of an awesome subset of JJ?

Input

The first line contains the number of test cases zz. The descriptions of the test cases follow.

The first line of each test case contains one integer nn (3≤n≤100 0003 \leq n \leq 100\,000), the number of vertices of the jellyfish.

Each of the next nn lines contains two integers uiu_i and viv_i (1≤ui≠vi≤n1 \leq u_i \neq v_i \leq n), describing one edge of the jellyfish. The given graph is guaranteed to be a jellyfish, and every two vertices are connected by at most one edge.

The total number of vertices in all test cases does not exceed 10610^6.

Output

For each test case, output a single line containing one integer, the maximum possible size of an awesome subset of the jellyfish.

Examples1

  1. Example 1

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