DFS

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

문제

You are given a rooted tree of nn vertices, and rr is the root of the tree. Each vertex xx has value a_xa\_x.

Let us define the DFS procedure starting from xx to find yy:

  1. Push xx on the stack.
  2. Check ww, the top element of the stack. If w=yw = y, the procedure ends. Otherwise, if there is at least one son of ww which is not visited, choose one such son with equal probability and push it on the stack.
  3. Repeat step 2 until there is no unvisited son.
  4. Pop the top element from the stack.
  5. Repeat step 2 until the stack is empty.

The procedure is legal if and only if yy is in the subtree of xx.

Define f(x,y)f(x,y) as the expectation of the minimum value of all vertices which were pushed on the stack during the DFS procedure starting from xx to find yy.

Now we want to calculate f(x,y)\sum f(x,y) for all legal pairs (x,y)(x,y). It can be shown that the answer can be expressed as an irreducible fraction xy\frac{x}{y}, where xx and yy are integers and y≢0(mod998,244,353)y\not \equiv 0\pmod {998\\,244\\,353}. Output the integer equal to xy1(mod998,244,353)x\cdot y^{-1}\pmod {998\\,244\\,353}. In other words, output an integer aa such that 0a<998,244,3530\leq a < 998\\,244\\,353 and ayx(mod998,244,353)a\cdot y\equiv x\pmod {998\\,244\\,353}.

입력

The first line contains an integer TT (1T1001 \leq T \leq 100), denoting the number of test cases.

For each test case, the first line contains two integers nn and rr (1n41051 \leq n \leq 4 \cdot 10^5, 1rn1 \leq r \leq n), denoting the number of vertices in the tree and the root.

The following line contains nn integers, the ii-th integer of them is a_ia\_i (1a_i1091\leq a\_i\leq 10^9) denoting the value of vertex ii.

Each of the next n1n-1 lines contains two integers uu and vv (1u,vn1 \leq u,v \leq n), denoting an edge of the tree.

It is guaranteed that n8105\sum n \leq 8 \cdot 10^5. It is also guaranteed that the given graph is indeed a tree.

출력

Output TT lines. Each line must contain one integer: the answer to the respective test case.