#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1001,mo=998244353;
int f[maxn][maxn],mn[maxn],a[maxn],pre[maxn],m,sz[maxn],g[maxn][maxn];
int qpow(int a,int b,int res=1){
    for(;b;b>>=1,a=a*a%mo)if(b&1)res=res*a%mo;
    return res;
}
void pr(int x){
}
vector<int>e[maxn],_e[maxn];
void predfs(int x,int fa){
    for(auto v:_e[x]){
        if(v==fa)continue;
        predfs(v,x);
        e[x].push_back(v);
    }
}
void dfs(int x,int fa){
    sz[x]=1;
    for(auto v:e[x]){
        dfs(v,x);
        mn[x]=min(mn[x],mn[v]);
        sz[x]+=sz[v];
    }
    for(auto v:e[x]){
        for(int j=1;j<=m;j++)(g[x][j]+=f[v][j]*sz[v]%mo)%=mo;
    }
   /* 
    for(int j=1;j<=m;j++)cout<<g[x][j]<<" ";cout<<endl;
    */
    sort(e[x].begin(),e[x].end(),[&](int x,int y){return mn[x]<mn[y];});
    memset(pre,0,sizeof(pre));
    for(int i=0;i<e[x].size();i++){
        int v=e[x][i];
        int p1=qpow((i)*(i+1)%mo,mo-2),p2=qpow((i+1)*(i+2)%mo,mo-2);
        int lim=min(a[x],mn[v]);
        for(int j=1;j<=m;j++){
            (f[x][min(lim,j)]+=pre[j]*p1%mo)%=mo;
            (pre[j]+=f[v][j]*sz[v]%mo)%=mo;
            (f[x][min(lim,j)]+=(g[x][j]-pre[j]+mo)%mo*p2%mo)%mo;
        }
    }
    //fa to sons to son
    
    for(auto v:e[x]){
        for(int j=1;j<=m;j++)
        (f[x][min(a[x],j)]+=sz[v]*qpow(e[x].size(),mo-2)%mo*f[v][j]%mo)%=mo;
    }
    //fa to first son

    (++f[x][a[x]])%=mo;
    //fa only
}
vector<int>s;
void solve(){
    int n,rt;
    memset(f,0,sizeof(f));
    memset(g,0,sizeof(g));
    scanf("%lld%lld",&n,&rt);
    s.resize(0);
    for(int i=1;i<=n;i++){
        e[i].resize(0);
        _e[i].resize(0);
        scanf("%lld",&a[i]);mn[i]=a[i];
        s.push_back(a[i]);
    }
    sort(s.begin(),s.end());s.erase(unique(s.begin(),s.end()),s.end());
    for(int i=1;i<=n;i++)a[i]=lower_bound(s.begin(),s.end(),a[i])-s.begin()+1;
    for(int i=1;i<n;i++){
        int x,y;scanf("%lld%lld",&x,&y);
        _e[x].push_back(y);_e[y].push_back(x);
    }
    m=s.size();
    predfs(rt,0);
    dfs(rt,0);
    int ans=0; 
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            (ans+=f[i][j]*s[j-1]%mo)%=mo;
        }
    }
    printf("%lld\n",ans);
        
}
int id[maxn],cnt[maxn];
signed main(){
freopen("dfs.in","r",stdin);
freopen("dfs.out","w",stdout);
       int T;
       scanf("%lld",&T);
       while(T--)solve();
}
