Under construction

Still being built. Things may change

Triples

Time limit7sMemory limit512 MB

Summary
Given a tree with up to 100,000 vertices in each of up to 20 test cases, count the unordered triples of vertices that are all at the same positive distance from each other.
Level

Medium7 of 10

Topics
Tree, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

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

Input

The first line contains the number of test cases zz (1≤z≤201 \leq z \leq 20). The descriptions of the test cases follow.

The first line of each test case contains the number of vertices nn (3≤n≤100 0003 \leq n \leq 100\,000). Each of the next n−1n - 1 lines contains two integers a,ba, b (1≤a,b≤n1 \leq a, b \leq n), meaning there is an edge between vertices aa and bb.

Output

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

Examples1

  1. Example 1

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