#include <bits/stdc++.h> 
using namespace std ; 
namespace hater_space { 

#define fp( i , x , y ) for( int i=(x); i<=(y); ++i ) 
#define fq( i , x , y ) for( int i=(y); i>=(x); --i ) 
#define i60 long long 
#define dou double 
#define u60 unsigned long long 
#define IL inline 
#define int long long 
const int mod = 998244353 , N = 4e5+10 ; 
vector <int> v[N] ; 
int a[N] , p[N] , n , rt , pre[N] , inv[N] ;    
IL bool cmp( int x , int y ) { return a[x] < a[y] ; } 
IL int R( int x ) { return x < mod ? x : x-mod ; } 
int qp( int A , int B ) { 
  int C=1 ; 
  for( ; B ; B>>=1 , A=1ll*A*A%mod ) if( B&1 ) C=1ll*A*C%mod ; 
  return C ; 
} 
void prep( int m ) { 
 // inv[0] = 1 ; 
  fp( i , 1 , m ) inv[i] = qp( i , mod-2 ) ; 
} 
void dfsp( int x , int fa ) { 
  pre[x] = fa ; 
  for( auto y : v[x] ) if( y != fa ) dfsp( y , x ) ; 
} 
bool is[N] , hs[N] ; 
int son[N] , vl[N] ;  
int lis[N] , len , Ans , al_sum , nw ; 
IL void dfs( int x , int nw ) { 
  if( is[x] ) return ; 
  al_sum = R( al_sum + nw ) ; 
  for( auto y : v[x] ) { 
    if( y == pre[x] ) continue ; 
    dfs( y , 1ll * nw * inv[son[x]-hs[y]+1] % mod ) ; 
  } 
} 
void solve( ) { 
  Ans = 0 ; 
  cin >> n >> rt ; 
  fp( i , 1 , n ) { 
    cin >> a[i] ; p[i] = i ; v[i].clear() ; 
    pre[i] = son[i] = 0 ; hs[i] = is[i] = 0 ; 
  } 
  sort( p+1 , p+1+n , cmp ) ; 
  int x , y , t ;  
  fp( i , 1 , n-1 ) { 
    cin >> x >> y ; 
    v[x].push_back(y) ; v[y].push_back(x) ; 
  } 
  dfsp( rt , 0 ) ; 
  fp( i , 1 , n ) { 
    x = p[i] ; len = 0 ; 
    while( x ) lis[++len] = x , x = pre[x] ; 
    al_sum = nw = 0 ; 
    fq( j , 1 , len ) { 
      nw = R( nw + 1 ) ; 
      if( is[lis[j]] ) nw = 0 ; 
      vl[j] = nw ; 
	  if( j == 1 ) break ; 
      nw = 1ll * nw * inv[son[lis[j]]-hs[lis[j-1]]+1] % mod ;  
	} 
	dfs( p[i] , nw ) ; 
//	cout << "T : " << al_sum << '\n' ; 
	fp( j , 1 , len ) { 
	  if( hs[lis[j]] ) break ; 
	//  cout << "H : " << lis[j] << ' ' << hs[lis[j]] << '\n' ; 
	  if( lis[j] != p[i] ) { 
        for( auto k : v[lis[j]] ) 
		  if( k != lis[j-1] ) { 
		    if( k == pre[lis[j]] ) continue ; 
		    // 进入这个子树的概率 且没进入lisj-1的概率 
		    assert( son[lis[j-1]] == 0 && j ) ; 
		    t = 1ll * ( inv[son[lis[j]]-hs[k]+1] + mod - inv[son[lis[j]]-hs[k]+2] ) * vl[j] % mod ; 
			// 进入这个子树的概率 
		//	cout << "K : " << k << ' ' << t << '\n' ; 
		    dfs( k , t ) ; 
		  } 
	  }  
	} 
	is[p[i]] = 1 ; 
	fp( j , 1 , len ) { 
	  if( hs[lis[j]] ) break ; 
	  hs[lis[j]] = 1 ; 
	  if( j != len ) son[lis[j+1]] ++ ; 
	} 
//	cout << a[p[i]] << ' '<< al_sum << ' ' << "2 : " << 2ll * al_sum % mod << '\n' ; 
	Ans = R( Ans + 1ll * al_sum * a[p[i]] % mod ) ; 
	fp( j , 1 , n ) { 
	  int cnt = 0 ; 
	  for( auto k : v[j] ) { 
	    if( k != pre[j] ) 
	    cnt += hs[k] ; 
	  } 
	  assert( cnt == son[j] ) ; 
	} 
  } 
  cout << Ans << '\n' ; 
} 
signed main( ) { 
  freopen( "dfs.in" , "r" , stdin ) ; 
  freopen( "dfs.out" , "w" , stdout ) ; 
  ios::sync_with_stdio(false) ; 
  cin.tie(0) ; 
  prep( 400005 ) ; 
  int T ; cin >> T ; 
  while( T -- ) solve( ) ; 
  return 0 ; 
} 

} 
signed main( ) { 
  hater_space::main() ; 
  return 0 ; 
} 
/*

1
5 1
5 4 3 2 1
1 2
1 3
3 4
3 5


*/
