The first line contains a single integer, representing the number of test cases.
For each test case, the first line contains a single integer, representing the number of cities.
Then n-1 lines follow, each line with two integers, representing a road between city u and city v.
The last line contains n integers, representing the initial award plan.
The input guarantees thatis a permutation of length n, and
.
For each test case, output a single line with a single integer, the number of possible award plans. The answer may be very large, you are only required to output the answer module 998244353.
For simplicity, we useto represent an award plan, where
represents the city of the i-th general. There are 7 possible award plans:
1. [2,1,5,4,3], without any exchange;
2. [1,2,5,4,3], achieved by exchanging between General (1,2);
3. [2,1,5,3,4], achieved by exchanging between General (4,5);
4. [1,2,5,3,4], achieved by exchanging between General (4,5), (1,2) in order;
5. [2,1,3,5,4], achieved by exchanging between General (4,5), (3,4) in order;
6. [1,2,3,5,4], achieved by exchanging between General (4,5), (3,4), (1,2) in order;
7. [2,3,1,5,4], achieved by exchanging between General (4,5), (3,4), (2,3) in order.