#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
int rd(){
	int x=0;char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))x=x*10+(ch-'0'),ch=getchar();
	return x;
}
void wr(int x,char ch='\n'){
	int sta[45],top=0;
	do sta[++top]=x%10,x/=10;while(x);
	for(int i=top;i;i--)putchar(sta[i]+'0');
	putchar(ch);
}
void solve(){
  int n=rd(),rt=rd()-1;
  vector<vector<int> >g(n);
  vector<int>a(n);
  generate(all(a),rd);
  rep(i,0,n-2){
    int x=rd()-1,y=rd()-1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  wr(0);
}
signed main(){
  freopen("dfs.in","r",stdin);
  freoprn("dfs.out","w",stdout);
  int T=rd();
  while(T--)solve();
}
