| Hello 2026 |
|---|
| Finished |
You have a tree rooted at node $$$1$$$ with $$$n$$$ nodes. Each node has a lowercase English letter written on it.
For each integer $$$i$$$ from $$$1$$$ to $$$n$$$, please solve the following problem independently:
You performed the above process exactly once for every possible path. Two paths are considered different if one node is visited in one path but not another.
Now, you have obtained many strings. You want to know the sum of the square of the number of occurrences for each type of string. Since this answer might be very large, output its value modulo $$$998\,244\,353$$$.
$$$^{\text{∗}}$$$A node $$$v$$$ is in another node $$$x$$$'s subtree if and only if the shortest path from node $$$1$$$ to node $$$v$$$ passes through node $$$x$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows.
For each test case, the first line contains an integer $$$n$$$ ($$$1 \le n \le 5000$$$).
The next line is a string of length $$$n$$$ containing only lowercase English letters, where the $$$i$$$-th character represents the letter on the $$$i$$$-th node.
This is followed by $$$n-1$$$ lines, each containing two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u,v \leq n, u \neq v$$$) representing an edge of the tree.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case, output $$$n$$$ numbers on a new line: the answer for $$$i=1,2,\ldots,n$$$, modulo $$$998\,244\,353$$$.
53abb1 21 32aa1 24ccbb1 22 32 44aaaa1 44 22 310cacbcccbac1 22 33 42 51 62 73 84 98 10
9 1 15 129 9 1 169 5 1 19185 65 19 3 1 1 1 3 1 1
For the first test case:
In the fourth test case, for node $$$1$$$, the possible strings are:
Therefore, the answer for node $$$1$$$ is $$$1^2+4^2+6^2+4^2=69$$$.
| Name |
|---|


