#include <bits/stdc++.h>
using namespace std ;

int read() {
	int f = 1 , j = 0 ; char c = getchar() ;
	while ( c < '0' || c > '9' ) { if ( c == '-' ) { f = -1 ; } c = getchar() ; }
	while ( c >= '0' && c <= '9' ) { j = ( j << 1 ) + ( j << 3 ) + ( c ^ 48 ) ; c = getchar() ; }
	return f * j ;
}

void write( int x ) {
	int l = 0 ; char c[200] ;
	if ( x < 0 ) { putchar('-') ; x = -x ; }
	do { c[++l] = x % 10 + 48 ; x /= 10 ; } while (x) ;
	do { putchar(c[l--]) ; } while (l) ;
	putchar('\n') ;
}

const int N = 1e6 + 10 ;

struct Edge {
	int to , nxt ;
} e[N] ;

int T , n , rt , tot , ans , head[N] , a[N] ;

void Build( int x , int y ) {
	e[++tot].to = y ; e[tot].nxt = head[x] ; head[x] = tot ;
	e[++tot].to = x ; e[tot].nxt = head[y] ; head[y] = tot ;
}

signed main() {
	freopen( "dfs.in" , "r" , stdin ) ; freopen( "dfs.out" , "w" , stdout ) ;
	T = read() ;
	while ( T --> 0 ) {
		n = read() ; rt = read() ;
		for ( int i = 1 ; i <= n ; i ++ ) { a[i] = read() ; }
		for ( int i = 1 ; i <= n - 1 ; i ++ ) {
			int x = read() , y = read() ; Build( x , y ) ;
		}
		int ans = 0 , mn = a[rt] ;
		for ( int i = 1 ; i <= n ; i ++ ) {
			if ( i == rt ) { continue ; }
			ans += min( rt , a[i] ) ;
			mn = min( mn , a[i] ) ;
		}
		ans += 2 * mn ; write(ans) ;
	}
}
