#P1930G. Prefix Max Set Counting

    ID: 10426 Type: RemoteJudge 5000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>data structuresdptrees*3100

Prefix Max Set Counting

Description

Define a function ff such that for an array bb, f(b)f(b) returns the array of prefix maxima of bb. In other words, f(b)f(b) is an array containing only those elements bib_i, for which bi=max(b1,b2,,bi)b_i=\max(b_1,b_2,\ldots,b_i), without changing their order. For example, f([3,10,4,10,15,1])=[3,10,10,15]f([3,10,4,10,15,1])=[3,10,10,15].

You are given a tree consisting of nn nodes rooted at 11.

A permutation^\dagger pp of is considered a pre-order of the tree if for all ii the following condition holds:

  • Let kk be the number of proper descendants^\ddagger of node pip_i.
  • For all xx such that i<xi+ki < x \leq i+k, pxp_x is a proper descendant of node pip_i.

Find the number of distinct values of f(a)f(a) over all possible pre-orders aa. Since this value might be large, you only need to find it modulo 998244353998\,244\,353.

^\dagger A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

^\ddagger Node tt is a proper descendant of node ss if sts \neq t and ss is on the unique simple path from tt to 11.

Each test contains multiple test cases. The first line contains a single integer tt (1t1051 \leq t \leq 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1061 \leq n \leq 10^6) — the number of vertices.

The following next n1n-1 lines contain two integers uu and vv (1u,vn1 \leq u, v \leq n, uvu \neq v) — denoting an edge between nodes uu and vv. It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

For each test case, output the number of distinct values of f(a)f(a) modulo 998244353998\,244\,353 that you can get.

Input

Each test contains multiple test cases. The first line contains a single integer tt (1t1051 \leq t \leq 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1061 \leq n \leq 10^6) — the number of vertices.

The following next n1n-1 lines contain two integers uu and vv (1u,vn1 \leq u, v \leq n, uvu \neq v) — denoting an edge between nodes uu and vv. It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

Output

For each test case, output the number of distinct values of f(a)f(a) modulo 998244353998\,244\,353 that you can get.

Sample Input 1

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

Sample Output 1

1
1
2
1
8
6

Note

In the first test case, the only valid pre-order is a=[1]a=[1]. So the only possible value of f(a)f(a) is [1][1].

In the second test case, the only valid pre-order is a=[1,2]a=[1,2]. So the only possible value f(a)f(a) is [1,2][1,2].

In the third test case, the two valid pre-orders are a=[1,2,3]a=[1,2,3] and a=[1,3,2]a=[1,3,2]. So the possible values of f(a)f(a) are [1,2,3][1,2,3] and [1,3][1,3].

In the fifth test case, the possible values of f(a)f(a) are:

  • [1,5][1,5];
  • [1,2,5][1,2,5];
  • [1,3,5][1,3,5];
  • [1,4,5][1,4,5];
  • [1,2,3,5][1,2,3,5];
  • [1,2,4,5][1,2,4,5];
  • [1,3,4,5][1,3,4,5];
  • [1,2,3,4,5][1,2,3,4,5].