#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=4e5+5;
const int p=998244353;

ll read(){static ll x;scanf("%lld",&x);return x;}
void write(ll x){printf("%lld",x);}
void print(ll x,char c='\n'){write(x),putchar(c);}

vector<int>val[N],e[N],id[N];
int a[N],b[N],fa[N],deep[N],now=0;
void dfs(int now,int father,int d)
{
	val[now].resize(deep[now]=d);
	for (int to:e[now])
	{
		if (to==father) continue;
		dfs(to,now,d+1);
	}
}

void work()
{
	int n=read(),root=read();
	for (int i=1;i<=n;i++) b[i]=a[i]=read();
	sort(b+1,b+1+n);
	int cnt=unique(b+1,b+1+n)-b-1;
	for (int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+1+b,a[i])-b;
	for (int i=1;i<=cnt;i++) id[i].clear();
	for (int i=1;i<=n;i++) id[a[i]].push_back(i);
	for (int i=1;i<=n;i++) val[i].clear(),e[i].clear();
	for (int i=1;i<n;i++)
	{
		int u=read(),v=read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(root,0,1);
	vector<int>ans(cnt+5);
	for (int i=cnt;i>=1;i--)
	{
		for (int j:id[i]) fix(j);
		ans[i]=now;
	}
	int res=0;
	for (int i=1;i<=cnt;i++) res=(res+1LL*(ans[i]-ans[i+1]+p)*b[i])%p;
	print(res);
}

signed main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	
	int T=read();
	while (T--) work();
	
	return 0;
}
