#include<bits/stdc++.h>
using namespace std;
const long long md=998244353;

int n,m;
vector <int> b[4000010],c[20];
int f[400010],mx[4000010],a[400010],ll[400010],rr[400010];
long long ans=0;

inline long long qsm(long long a,long long b)
{
	long long ret=1;
	for (;b;b>>=1)
	{
		if (b&1) ret=ret*a%md;
		a=a*a%md;
	}
	return ret;
}

void dfs(int t,int o)
{
	mx[t]=a[t];
	f[t]=o;
	for (auto to:b[t])
	{
		if (to==o) continue;
		dfs(to,t);
		mx[t]=min(mx[t],mx[to]);
	}
}

int main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	int T;
	scanf("%d",&T);
	while (T--)
	{
		ans=0;
		scanf("%d%d",&n,&m);
		if (n<=10)
		{
			for (int i=1;i<=n;i++)
			{
				b[i].clear();
				c[i].clear();
				scanf("%d",&a[i]);
			}
			for (int i=1;i<n;i++)
			{
				int x,y;
				scanf("%d%d",&x,&y);
				b[x].push_back(y);
				b[y].push_back(x);
			}
			dfs(m,0);
			for (int i=1;i<=n;i++)
			{
				int s=i;
				while (s!=0)
				{
					c[s].push_back(i);
					s=f[s];
				}
			}
			for (int l=1;l<=n;l++)
			{
				m=l;
				for (auto i:c[l])
				{
					long long ret=0;
					vector<int> ve;
					int t=i;
					int mxx=a[t];
					while (t!=m)
					{
						int s=t;
						t=f[t];
						mxx=min(mxx,a[t]);
						for (auto to:b[t])
						{
							if (to==f[t]||to==s) continue;
							ve.push_back(mx[to]);
						}
					}
					int ss=ve.size();
					long long cnt=(1<<ss);
					for (int j=0;j<(1<<ss);j++)
					{
						int mmx=mxx;
						for (int k=0;k<ss;k++)
						{
							if (j&(1<<k))
							{
								mmx=min(mmx,ve[k]);
							}
						}
						ret+=mmx;
					}
					ans=(ans+ret*qsm(cnt,md-2))%md;
				}
			}
			printf("%lld\n",ans);
		}
		else
		{
			for (int i=1;i<=n;i++)
			{
				b[i].clear();
				scanf("%d",&a[i]);
			}
			for (int i=1;i<n;i++)
			{
				int x,y;
				scanf("%d%d",&x,&y);
				b[x].push_back(y);
				b[y].push_back(x);
			}
			dfs(m,0);
			vector <int> ve;
			ve.push_back(0);
			int id=m;
			for (int i=1;i<=n;i++)
			{
				if (b[i].size()==1&&i!=m)
				{
					id=i;
					break;
				}
			}
			for (int i=1;i<=n;i++)
			{
				ve.push_back(a[id]);
				id=f[id];
			}
			ve.push_back(0);
			for (int i=1;i<=n;i++)
			{
				int l=i;
				while (ve[i]<=ve[l-1]) l=ll[l-1];
				ll[i]=l;
			}
			for (int i=n;i>=1;i--)
			{
				int r=i;
				while (ve[i]<ve[r+1]) r=rr[r+1];
				rr[i]=r;
			}
			for (int i=1;i<=n;i++)
			{
//				cout<<i<<"  "<<ll[i]<<"   "<<rr[i]<<endl;
				ans=(ans+(i-ll[i]+1)*(rr[i]-i+1)*ve[i])%md;
//				cout<<i<<"   "<<ans<<endl;
			}
//			cout<<ans<<endl;
			printf("%lld\n",ans);
		}
	}
	return 0;
}
