// This Code was made by Chinese_zjc_.
#include<bits/stdc++.h>
const int MOD = 998244353;
struct mint
{
    unsigned v;
    mint(unsigned v_=0):v(v_){}
    mint&operator+=(const mint &X){return (v+=X.v)>=MOD?v-=MOD:v,*this;}
    mint&operator-=(const mint &X){return (v+=MOD-X.v)>=MOD?v-=MOD:v,*this;}
    mint&operator*=(const mint &X){return v=1llu*v*X.v%MOD,*this;}
    mint&operator/=(const mint &X){return *this*=X.inv();}
    mint pow(long long B)const
    {
        B%=MOD-1;
        if(B<0)
            B+=MOD-1;
        mint res=1,A=*this;
        while(B)
        {
            if(B&1)
                res*=A;
            A*=A;
            B>>=1;
        }
        return res;
    }
    mint inv()const{return pow(MOD-2);}
    friend mint operator+(const mint &A,const mint &B){return mint(A)+=B;}
    friend mint operator-(const mint &A,const mint &B){return mint(A)-=B;}
    friend mint operator*(const mint &A,const mint &B){return mint(A)*=B;}
    friend mint operator/(const mint &A,const mint &B){return mint(A)/=B;}
    friend std::istream&operator>>(std::istream&A,mint &B){return A>>B.v;}
    friend std::ostream&operator<<(std::ostream&A,const mint &B){return A<<B.v;}
    friend bool operator==(const mint &A,const mint &B){return A.v==B.v;}
}dp[400005],fact[400005],ifact[400005],a[400005],b[400005],ans,sum;
int T,n,root,fa[400005],y[400005],w[400005],rk[400005],cur;
std::vector<int> son[400005];
bool bad[400005];
void init(int now)
{
    for(std::size_t i=0;i!=son[now].size();++i)
    {
        int &v=son[now][i];
        if(v==fa[now])
        {
            std::swap(son[now][i--],son[now].back());
            son[now].pop_back();
            continue;
        }
        fa[v]=now;
        init(v);
    }
}
mint d(int x,int y){return x>=y?fact[x]*ifact[x-y]:0;}
mint id(int x,int y){return x>=y?ifact[x]*fact[x-y]:0;}
void get(int now)
{
    a[now]=b[now]=0;
    for(int i=0;i<=y[now];++i)
        a[now]+=d(y[now],i)*id(son[now].size(),i+1);
    for(int i=0;i<=y[now]-1;++i)
        b[now]+=d(y[now]-1,i)*id(son[now].size(),i+1);
}
void calc(int now)
{
    if(w[now]>cur)
    {
        dp[now]=1;
        for(auto i:son[now])
            if(bad[i])
                dp[now]+=a[now]*dp[i];
            else
                dp[now]+=b[now]*dp[i];
    }
    else
        dp[now]=0;
}
void dfs(int now)
{
    for(auto i:son[now])
        dfs(i);
    calc(now);
}
signed main()
{
    freopen("dfs.in","r",stdin)&&freopen("dfs.out","w",stdout);
    std::ios::sync_with_stdio(false);
    fact[0]=1;
    for(int i=1;i<=400000;++i)
        fact[i]=fact[i-1]*i;
    ifact[400000]=fact[400000].inv();
    for(int i=400000;i;--i)
        ifact[i-1]=ifact[i]*i;
    std::cin>>T;
    while(T--)
    {
        std::cin>>n>>root;
        for(int i=1;i<=n;++i)
            std::cin>>w[i];
        for(int i=1,u,v;i!=n;++i)
            std::cin>>u>>v,son[u].push_back(v),son[v].push_back(u);
        init(root);
        for(int i=1;i<=n;++i)
            y[i]=son[i].size();
        std::iota(rk+1,rk+1+n,1);
        std::sort(rk+1,rk+1+n,[&](const int &A,const int &B){return w[A]<w[B];});
        std::fill(bad+1,bad+1+n,false);
        cur=0;
        for(int i=1;i<=n;++i)
            get(i);
        dfs(root);
        for(int i=1;i<=n;++i)
            sum+=dp[i];
        for(int i=1;i<=n;++i)
        {
            cur=w[rk[i]];
            ans+=(w[rk[i]]-w[rk[i-1]])*sum;
            int j=rk[i];
            while(!bad[j])
            {
                bad[j]=true;
                --y[fa[j]];
                get(fa[j]);
                j=fa[j];
            }
            dfs(root);
            sum=0;
            for(int i=1;i<=n;++i)
                sum+=dp[i];
        }
        std::cout<<ans<<std::endl;
        ans=sum=0;
        for(int i=1;i<=n;++i)
            son[i].clear(),fa[i]=0;
    }
    return 0;
}