#P1830D. Mex Tree

Mex Tree

No submission language available for this problem.

Description

You are given a tree with nn nodes. For each node, you either color it in 00 or 11.

The value of a path (u,v)(u,v) is equal to the MEX^\dagger of the colors of the nodes from the shortest path between uu and vv.

The value of a coloring is equal to the sum of values of all paths (u,v)(u,v) such that 1uvn1 \leq u \leq v \leq n.

What is the maximum possible value of any coloring of the tree?

^{\dagger} The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:

  • The MEX of [2,2,1][2,2,1] is 00, because 00 does not belong to the array.
  • The MEX of [3,1,0,1][3,1,0,1] is 22, because 00 and 11 belong to the array, but 22 does not.
  • The MEX of [0,3,1,2][0,3,1,2] is 44 because 00, 11, 22, and 33 belong to the array, but 44 does not.

Each test contains multiple test cases. The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of nodes in the tree.

The following n1n-1 lines of each test case contains 22 integers aia_i and bib_i (1ai,bin,aibi1 \leq a_i, b_i \leq n, a_i \neq b_i) — indicating an edge between vertices aia_i and bib_i. It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of nn across all test cases does not exceed 21052 \cdot 10^5.

For each test case, print the maximum possible value of any coloring of the tree.

Input

Each test contains multiple test cases. The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of nodes in the tree.

The following n1n-1 lines of each test case contains 22 integers aia_i and bib_i (1ai,bin,aibi1 \leq a_i, b_i \leq n, a_i \neq b_i) — indicating an edge between vertices aia_i and bib_i. It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of nn across all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, print the maximum possible value of any coloring of the tree.

Sample Input 1

4
3
1 2
2 3
4
1 2
1 3
1 4
10
1 2
1 3
3 4
3 5
1 6
5 7
2 8
6 9
6 10
1

Sample Output 1

8
15
96
1

Note

In the first sample, we will color vertex 22 in 11 and vertices 1,31,3 in 00. After this, we consider all paths:

  • (1,1)(1,1) with value 11
  • (1,2)(1,2) with value 22
  • (1,3)(1,3) with value 22
  • (2,2)(2,2) with value 00
  • (2,3)(2,3) with value 22
  • (3,3)(3,3) with value 11

We notice the sum of values is 88 which is the maximum possible.