Today, Rikka is playing a strategic game. She has finished the first stage of the game: She has already established her own country.
Rikka owns n cities, connected by n−1 bidirectional roads. Any two cities are reachable through the roads. Rikka decides to award these cities to n loyal generals. These generals are labeled from 1 to n according to the increasing order of their contributions. Initially, Rikka decides to award the i-th city to the p_i-th general, where p_1,p_2,…,p_n is a permutation of length n.
Then, Rikka summons all the generals and shows them the initial plan. Generals are allowed to exchange their cities under two restrictions. General u with city a can change his/her city with general v with city b if and only if:
During the exchange process, one general is allowed to change his/her city many times, and also, one city may be exchanged among many generals.
Not surprised, a quarrel broke out between the generals. It seems that it will take a long time to determine the ownership of the cities. All these things make Rikka bored. To make fun, Rikka wants you to calculate the number of possible award plans.
The first line contains a single integer t (1≤t≤2×105), representing the number of test cases.
For each test case, the first line contains a single integer n (1≤n≤2×105), representing the number of cities.
Then n−1 lines follow, each line with two integers u,v (1≤u,v≤n), representing a road between city u and city v.
The last line contains n integers p_i (1≤p_i≤n), representing the initial award plan.
The input guarantees that p_1,p_2,…,p_n is a permutation of length n, and ∑n≤2×105.
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 use \[a_1,…,a_n] to represent an award plan, where a_i represents the city of the i-th general. There are 7 possible award plans: