eolymp
bolt
Try our new interface for solving problems
Problems

Triples

Triples

You are given a tree, i.e. a connected undirected graph with no cycles. For every two vertices x, y let d(x, y) denote the length (i.e. the number of edges) of the unique simple path between x and y. Count all the (unordered) triples {x, y, z} such that d(x, y) = d(y, z) = d(z, x) > 0.

Input

The first line contains the number of test cases z (1z20). The descriptions of the test cases follow.

The first line of every test case contains the number of vertices n (3n100 000). Each of the next n - 1 lines contains two integers a, b (1a, bn), denoting that there is an edge between vertices a and b.

Output

For each test case output one integer: the number of triples in question.

Time limit 10 seconds
Memory limit 128 MiB
Input example #1
2
4
1 2
1 3
1 4
8
1 2
1 3
1 4
2 5
2 6
3 7
4 8
Output example #1
1
4
Source 2018 Petrozavodsk, Winter, Jagiellonian U, January 30, Problem K