Codeforces Round 891 (Div. 3) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

combinatorics

divide and conquer

dsu

graphs

greedy

sortings

trees

*2000

No tag edit access

The problem statement has recently been changed. View the changes.

×
G. Counting Graphs

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputGiven a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph without cycles. Each edge of the tree has its weight, $$$w_i$$$.

Your task is to count the number of different graphs that satisfy all four conditions:

- The graph does not have self-loops and multiple edges.
- The weights on the edges of the graph are integers and do not exceed $$$S$$$.
- The graph has exactly one minimum spanning tree.
- The minimum spanning tree of the graph is the given tree.

Two graphs are considered different if their sets of edges are different, taking into account the weights of the edges.

The answer can be large, output it modulo $$$998244353$$$.

Input

The first line contains an integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.

The first line of each test case contains two integers $$$n$$$ and $$$S$$$ ($$$2 \le n \le 2 \cdot 10^5, 1\le S\le 10^9$$$) — the number of vertices and the upper bound of the weights.

Then follow $$$n-1$$$ lines describing the tree, the $$$i$$$-th line contains three integers $$$u_i$$$, $$$v_i$$$, and $$$w_i$$$ ($$$1\le u_i,v_i\le n, u_i \ne v_i, 1\le w_i\le S$$$) — an edge in the tree with weight $$$w_i$$$.

It is guaranteed that the sum of $$$n$$$ for all tests does not exceed $$$2\cdot 10^5$$$.

Output

For each test, output the number of different graphs that satisfy the conditions, modulo $$$998244353$$$.

Example

Input

42 51 2 44 51 2 22 3 43 4 35 61 2 31 3 23 4 63 5 110 2001 2 32 3 333 4 2001 5 1325 6 15 7 297 8 1877 9 207 10 4

Output

1 8 80 650867886

Note

In the first sample, there is only one graph, which is the given tree.

In the second samle, the given tree looks like this:

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/18/2024 14:24:24 (l2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|