#define ssh(x)<x>
#include ssh(bits/stdc++.h)
#define rfor(x...)for(register x)
#define rep(i,l,r)rfor(ll i=l;i<=r;i++)
#define ref(i,l,r)rfor(ll i=l;i<r;i++)
#define per(i,l,r)rfor(ll i=l;i>=r;i--)
#define rev(i,u,v)rfor(ll i=head[u],v;v=to[i],i;i=next[i])
#define rej(i,s)rfor(ll i=s;i;i=(i-1)&(s))
#define red(i,n)rfor(ll i=n;i;i>>=1)
#define IO(x...)((*#x!='/'||#x[1])&&(*#x&&freopen(#x".in","r",stdin)&&freopen(#x".out","w",stdout),gc=fgc,pc=fpc,atexit(fout)))
typedef long long ll;
typedef const ll cll;
typedef unsigned long long ull;
cll N=1e6+7,mod=998244353,iz=1<<21,oz=1<<22;
typedef ll aN[N];
char is[iz],*i1=is,*i2=is,os[oz],*o1=os,*o2=os+oz;
int fgc(){
    return i1==i2&&is==(i2=is+fread(i1=is,1,iz,stdin))?-1:*i1++;
}
void fout(){
    fwrite(os,o1-os,1,stdout),o1=os;
}
int fpc(int c){
    if(o1==o2)fout();
    return*o1++=c;
}
int(*gc)()=getchar,(*pc)(int)=putchar,wt[126];
int readchar(int l=33,int r=126){
    if(l>r)std::swap(l,r);
    int c=gc();
    for(;c<l||c>r;c=gc());
    return c;
}
ll readll(){
    ll x=0,w=1;
    int c=gc();
    for(;c<48||c>57;c=gc())c-45||(w=-w);
    for(;c>47&&c<58;c=gc())x=x*10+c-48;
    return x*w;
}
void writell(cll u,int c=32){
    int t=0;
    rfor(ull n=u<0?pc(45),0ull-u:u;n;n/=10)wt[++t]=n%10^48;
    for(t||pc(48);t;)pc(wt[t--]);
    c&&pc(c);
}
int mygets(char*s,int c=0){
    char*t=s+1;
    while((*s=gc())<33);
    while((*t=gc())>32)t++;
    c&&(*t++=c),*t=0;
    return t-s;
}
int myputs(const char*s,int c=10){
    const char*t=s;
    while(*t)pc(*t++);
    c&&pc(c);
    return t-s+(c!=0);
}
cll IO_res=IO(dfs),T=readll();
aN next,to,head,f,a,mn,inv,njc,is_v;
ll cnt;
void add(cll u,cll v){
    next[++cnt]=head[u],to[head[u]=cnt]=v;
}
ll minsum,g;
void dfs(cll u,cll fa){
    f[u]=fa,mn[u]=a[u];
    rev(i,u,v)if(v^fa)dfs(v,u),mn[u]=std::min(mn[u],mn[v]);
}
void dfs_10(cll u,cll fa,ll minnow,cll gl){
    //printf("%lld %lld g=%lld %d\n",u,fa,g,u==g);
        //printf("???");
    minnow=std::min(minnow,a[u]);
    if(u==g){
        //printf("???");
        //printf("%lld %lld\n",minnow,gl);
        minsum+=minnow*gl%mod;
        return;
    }
    ll son[10],t=0;
    rev(i,u,v)if(v^fa)son[++t]=v;
    std::sort(son+1,son+t+1);
    do{
        ll min=minnow;
        rep(i,1,t){
            if(is_v[son[i]])dfs_10(son[i],u,min,gl*njc[t]%mod);
            else min=std::min(min,mn[son[i]]);
        }
    }while(std::next_permutation(son+1,son+t+1));
}
void calc(){
    cll n=readll(),root=readll();
    memset(head,cnt=0,(n+1)<<3);
    rep(i,1,n)a[i]=readll();
    rep(i,2,n){
        cll u=readll(),v=readll();
        add(u,v),add(v,u);
    }
    dfs(root,0);
    //rep(i,1,n)printf("%lld\n",mn[i]);
    if(n<=10){
        ll sum=0;
        rep(j,1,n){
            rfor(ll u=j;u;u=f[u]){
                is_v[u]=1;
                g=j,minsum=0,dfs_10(u,f[u],mod,1);
                sum+=minsum;
            }
            rfor(ll u=j;u;)is_v[u]=0,u=f[u];
        }
        writell(sum%mod,10);
        return;
    }
    /*
    static aN d;
    rep(u,1,n)rev(i,u,v)d[v]++;
    if(d[root]==n-1){
        
    }
    */
}
int main(){
    inv[1]=1,njc[0]=1;
    rep(i,2,N-1)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    rep(i,1,N-1)njc[i]=njc[i-1]*inv[i]%mod;//,printf("%lld\n",njc[i]);
    rep(i,1,T)calc();
    return 0;
}//Cc!FN0I$w3ILAIKeQI?
/*
4
1 1
1
3 3
3 3 4
3 1
3 2
6 1
5 2 4 1 3 6
1 2
1 6
2 3
2 4
4 5
5 1
5 4 3 2 1
1 2
1 3
3 4
3 5
*/
