#P1930G. Prefix Max Set Counting
Prefix Max Set Counting
Description
Define a function such that for an array , returns the array of prefix maxima of . In other words, is an array containing only those elements , for which , without changing their order. For example, .
You are given a tree consisting of nodes rooted at .
A permutation of is considered a pre-order of the tree if for all the following condition holds:
- Let be the number of proper descendants of node .
- For all such that , is a proper descendant of node .
Find the number of distinct values of over all possible pre-orders . Since this value might be large, you only need to find it modulo .
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
Node is a proper descendant of node if and is on the unique simple path from to .
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of vertices.
The following next lines contain two integers and (, ) — denoting an edge between nodes and . It is guaranteed that the given edges form a tree.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output the number of distinct values of modulo that you can get.
Input
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of vertices.
The following next lines contain two integers and (, ) — denoting an edge between nodes and . It is guaranteed that the given edges form a tree.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the number of distinct values of modulo that you can get.
Note
In the first test case, the only valid pre-order is . So the only possible value of is .
In the second test case, the only valid pre-order is . So the only possible value is .
In the third test case, the two valid pre-orders are and . So the possible values of are and .
In the fifth test case, the possible values of are:
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- .