#include<algorithm>
#include<cstdio>
int T,n,root,val[400010],u,v,head[400010],cnt;
long long ans;
struct Edge{
	int from,to,next;
}edge[800010];
void add_edge(int u,int v)
{
	edge[++cnt] = (Edge){u,v,head[u]},head[u] = cnt;
}
int main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d%d",&n,&root),ans = 0;
		for (int i = 1;i <= n;++i)
			scanf("%d",val[i]);
		for (int i = 1;i < n;++i)
			scanf("%d%d",&u,&v),add_edge(u,v),add_edge(v,u);
		for (int i = 1;i <= n;++i)
			if (i != root)
				ans += std::min(val[i],val[root]);
		printf("%lld\n",ans);
	}
	return 0;
}
