#include<bits/stdc++.h>
using namespace std;
int T,n,r,a[1000005];
int main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n>>r;
		for(int i=1;i<=n;i++)scanf("%d",&a[i]);
		for(int i=1;i<n;i++){
			int x,y;
			scanf("%d%d",&x,&y);
		}cout<<a[r]<<"\n";
	}
}
