Rikka with Generals

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

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 nn cities, connected by n1n-1 bidirectional roads. Any two cities are reachable through the roads. Rikka decides to award these cities to nn loyal generals. These generals are labeled from 11 to nn according to the increasing order of their contributions. Initially, Rikka decides to award the ii-th city to the p_ip\_i-th general, where p_1,p_2,,p_np\_1, p\_2, \dots, p\_n is a permutation of length nn.

Then, Rikka summons all the generals and shows them the initial plan. Generals are allowed to exchange their cities under two restrictions. General uu with city aa can change his/her city with general vv with city bb if and only if:

  • The contributions of general uu and general vv are close, i.e. uv|u-v| should be equal to 11;
  • The geometric positions of city aa and city bb are close, i.e. there should be a road between city aa and city bb

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 (1t2×105)t\ (1 \leq t \leq 2 \times 10^5), representing the number of test cases.

For each test case, the first line contains a single integer n (1n2×105)n\ (1 \leq n \leq 2\times 10^5), representing the number of cities.

Then n1n-1 lines follow, each line with two integers u,v (1u,vn)u,v\ (1 \leq u,v \leq n), representing a road between city uu and city vv.

The last line contains nn integers p_i (1p_in)p\_i\ (1 \leq p\_i \leq n), representing the initial award plan. 

The input guarantees that p_1,p_2,,p_np\_1, p\_2, \dots, p\_n is a permutation of length nn, and n2×105\sum n \leq 2 \times 10^5.

출력

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 998244353998244353.

힌트

For simplicity, we use \[a_1,,a_n]\[a\_1, \dots, a\_n] to represent an award plan, where a_ia\_i represents the city of the ii-th general. There are 77 possible award plans:

  • \[2,1,5,4,3]\[2,1,5,4,3], without any exchange;
  • \[1,2,5,4,3]\[1,2,5,4,3], achieved by exchanging between General (1,2)(1,2);
  • \[2,1,5,3,4]\[2,1,5,3,4], achieved by exchanging between General (4,5)(4,5);
  • \[1,2,5,3,4]\[1,2,5,3,4], achieved by exchanging between General (4,5)(4,5), (1,2)(1,2) in order;
  • \[2,1,3,5,4]\[2,1,3,5,4], achieved by exchanging between General (4,5)(4,5), (3,4)(3,4) in order;
  • \[1,2,3,5,4]\[1,2,3,5,4], achieved by exchanging between General (4,5)(4,5), (3,4)(3,4), (1,2)(1,2) in order;
  • \[2,3,1,5,4]\[2,3,1,5,4], achieved by exchanging between General (4,5)(4,5), (3,4)(3,4), (2,3)(2,3) in order.