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

#define ll long long
#define ull unsigned long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define SZ(a) ((int)a.size())
#define pb push_back
#define fir first
#define sec second

inline int read(){
    int x=0,f=0;char ch=getchar();
    while(!isdigit(ch))f|=ch=='-',ch=getchar();
    while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
    return f?-x:x;
}
template<typename T> void print(T x){
    if(x<0)putchar('-'),x=-x;
    if(x>=10)print(x/10);
    putchar(x%10+'0');
}
template<typename T> void print(T x,char ch){
    print(x),putchar(ch);
}

const int N=255;
const int mod=998244353;

vector<int> adj[N];
int dad[N],tree[N],n,rt,a[N];

void dfs1(int u,int fa){
    dad[u]=fa,tree[u]=a[u];
    for(auto v:adj[u]){
        if(v==fa)continue;
        dfs1(v,u);
        tree[u]=min(tree[u],tree[v]);
    }
}

int ans,inv[N];
void dfs2(int u,int P,int now){
    now=min(now,a[u]);
    ans=(ans+1ll*P*now)%mod;
    vector<int> tmp;
    for(auto v:adj[u]){
        if(v==dad[u])continue;
        tmp.pb(v);
    }
    sort(tmp.begin(),tmp.end());
    do{
        int ways=1;
        for(int i=1;i<=SZ(tmp);i++)ways=1ll*ways*inv[i]%mod;
        int _=now;
        for(auto v:tmp){    
            dfs2(v,1ll*P*ways%mod,_);
            _=min(_,tree[v]);
        }
    }while(next_permutation(tmp.begin(),tmp.end()));
}

void solve(){
    scanf("%d%d",&n,&rt);
    ans=0;
    rep(i,1,n)adj[i].clear();
    rep(i,1,n)a[i]=read();
    rep(i,1,n-1){
        int u=read(),v=read();
        adj[u].pb(v),adj[v].pb(u);
    }
    dfs1(rt,0);
    rep(i,1,n){
        dfs2(i,1,a[i]);
    }
    printf("%d\n",ans);
}

int main(){
    inv[1]=1;rep(i,2,N-1)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    int T;scanf("%d",&T);
    while(T--)solve();
    return 0;
}

/*
1
4 1
1 2 3 4
1 2
1 3
1 4
*/