#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int kcz=998244353;
const int maxn=400005;
int n,rt,he[maxn],ne[maxn<<1],to[maxn<<1],tot,t[maxn],cnt[maxn]/*[2]*/;
ll inv[maxn],/*fac[maxn],invfac[maxn],*/a[maxn],b[maxn],ans,s,f[maxn];
inline void add_edge(int u,int v) { to[tot]=v,ne[tot]=he[u],he[u]=tot++; }
void dfs(int u,int fa,int cur)
{
    int i;
    /*cnt[u][0]=cnt[u][1]=0,*/cnt[u]=0,t[u]=(a[u]>=cur);
    for(i=he[u];~i;i=ne[i])
        if(to[i]!=fa)
            dfs(to[i],u,cur),t[u]&=t[to[i]];
    // cnt[fa][t[u]]++;
    cnt[fa]+=!t[u];
}
// a X, b Y, 1 Z
// no X in front of Z
// sum(i=0 to b,C(a+b-i,a))/(a+b+1)!*a!*b!
// sum(i=0 to b,C(a+b-i,a))=sum(i=0 to b,C(a+i,a))
//=sum(i=0 to b,C(a+i,a)C(b-i,0))=C(a+b+1,a+1) // first X to Z
// (a+b+1)!/(a+1)!/b!/(a+b+1)!*a!*b!=1/(a+1)
void calc(int u,int fa,int cur)
{
    int i;
    (s+=(f[u]=(a[u]>=cur)?(1+f[fa]*inv[cnt[fa]-(!t[u])+1])%kcz:0))%=kcz;
    for(i=he[u];~i;i=ne[i])
        if(to[i]!=fa)
            calc(to[i],u,cur);
}
int main()
{
    int T,i,u,v;
    freopen("dfs.in","r",stdin),freopen("dfs.out","w",stdout);
    for(inv[1]=/*fac[0]=fac[1]=invfac[0]=invfac[1]=*/1,i=2;i<maxn;i++)
        inv[i]=kcz-(kcz/i)*inv[kcz%i]%kcz;
        // fac[i]=fac[i-1]*i%kcz,
        // invfac[i]=invfac[i-1]*inv[i]%kcz;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&rt);
        for(tot=0,i=1;i<=n;i++) he[i]=-1,scanf("%lld",&a[i]),b[i]=a[i];
        for(i=1;i<n;i++) scanf("%d%d",&u,&v),add_edge(u,v),add_edge(v,u);
        b[0]=0,sort(b+1,b+n+1),/*cnt[0][0]=cnt[0][1]=0*/cnt[0]=0;
        for(i=1,ans=0;i<=n;i++)
            s=0,f[0]=0,dfs(rt,0,b[i]),calc(rt,0,b[i]),(ans+=s*(b[i]-b[i-1]))%=kcz;
        printf("%lld\n",ans);
    }
    fclose(stdin),fclose(stdout);
    return 0;
}