//998244353,998244353,998244353
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read()
{
    int r=0;
    char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') r=r*10+c-48,c=getchar();
    return r;
}
const int p=998244353;
int qp(int x,int y)
{
    int r=1;
    for(int a=x; y; y>>=1,a=1ll*a*a%p) (y&1)&&(r=1ll*r*a%p);
    return r;
}
vector<int> e[400003],v[400003],vv[400003];
int a[400003],lsh[400003],sz[400003],mn[400003],f[400003],son[400003],inv[400003];
bool A[400003];
void dfs(int x,int fa)
{
    sz[x]=1,mn[x]=a[x],f[x]=fa;
    for(int y:e[x]) if(y!=fa) dfs(y,x),sz[x]+=sz[y],(mn[x]>mn[y])&&(mn[x]=mn[y]);
    return ;
}
int g[400003],b[400003];
void calc(int x,int fa,int d)
{
    g[x]=1;
    for(int y:e[x]) if(y!=fa) calc(y,x,d),g[x]=(g[x]+1ll*g[y]*inv[son[x]+1-A[y]])%p;
    if(a[x]<d) g[x]=0;
    return ;
}
int pre[400003];
int h[400003];
const int z=(p+1)>>1;
signed main()
{
#ifndef local
    freopen("dfs.in","r",stdin);
    freopen("dfs.out","w",stdout);
#endif
    for(int i=1; i<=400000; ++i) inv[i]=qp(i,p-2);
    h[0]=1;
    for(int i=1; i<=400000; ++i) h[i]=1ll*h[i-1]*z%p;
    for(int T=read(); T--;)
    {
        int n=read(),rt=read(),ans=0;
        for(int i=1; i<=n; ++i) lsh[i]=a[i]=read(),A[i]=son[i]=0,e[i].clear();
        for(int i=1,u,v; i<n; ++i) u=read(),v=read(),e[u].push_back(v),e[v].push_back(u);
        if((int)e[rt].size()==n-1)
        {
            int ans=0,S=0;
            for(int i=1; i<=n; ++i) ans=(ans+a[i])%p;
            for(int i=1; i<=n; ++i) if(i!=rt) b[++S]=min(a[i],a[rt]);
            sort(b+1,b+S+1);
            for(int i=1; i<=S; ++i) pre[i]=(pre[i-1]+1ll*b[i]*h[i])%p;
            for(int i=1; i<=S; ++i) ans=(1ll*h[i-1]*b[i]+ans+pre[i-1])%p;
            printf("%d\n",ans);
            continue;
        }
        sort(lsh+1,lsh+n+1);
        int m=unique(lsh+1,lsh+n+1)-lsh-1,sum=0;
        for(int i=1; i<=m; ++i) v[i].clear(),vv[i].clear();
        for(int i=1; i<=n; ++i) a[i]=lower_bound(lsh+1,lsh+m+1,a[i])-lsh;
        dfs(rt,0),calc(rt,0,0);
        for(int i=1; i<=n; ++i) sum=(sum+g[i])%p;
        for(int i=1; i<=n; ++i) v[mn[i]].push_back(i),vv[a[i]].push_back(i);
        for(int d=1; d<=m; ++d) //ans>=i
        {
            for(int i:v[d-1]) 
            {
                A[i]=1,++son[f[i]];
                for(int x=i; x; x=f[x])
                {
                    sum=(sum+p-g[x])%p,g[x]=1;
                    for(int y:e[x]) if(y!=f[x]) g[x]=(g[x]+1ll*g[y]*inv[son[x]+1-A[y]])%p;
                    if(a[x]<d) g[x]=0;
                    sum=(sum+g[x])%p;
                }
            }
            for(int i:vv[d-1]) 
            {
                for(int x=i; x; x=f[x])
                {
                    sum=(sum+p-g[x])%p,g[x]=1;
                    for(int y:e[x]) if(y!=f[x]) g[x]=(g[x]+1ll*g[y]*inv[son[x]+1-A[y]])%p;
                    if(a[x]<d) g[x]=0;
                    sum=(sum+g[x])%p;
                }
            }
            ans=(ans+1ll*(lsh[d]-lsh[d-1])*sum)%p;
        }
        printf("%d\n",ans);
    }
    return 0;
}