#include<bits/stdc++.h>
#define MAXX 300009
using namespace std;
using ll= long long int ;
ll hell= 1000000000+7;


int main(){
	    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 	
	ll t; cin>>t;
	while(t--){
		ll n; cin>>n;
		
		ll w[n];
		ll ans=0;
		ll deg[n];
		vector<ll> s;
		for(ll i=0;i<n;++i){
			cin>>w[i];
			ans+=w[i];
			deg[i]=0;
		}

		for(ll i=0;i<n-1;++i){
			ll x,y; cin>>x>>y;
			x--;
			y--;
			deg[x]++;
			deg[y]++;
		}
		for(ll i=0;i<n;++i){
			for(ll j=1;j<deg[i];++j){
				s.push_back(w[i]);
			}

		}
		cout<<ans<<" ";
		sort(s.begin(),s.end());
		reverse(s.begin(),s.end());
		for(auto i: s){
			ans+= i;
			cout<<ans<<" ";
		}
		cout<<endl;

	}
	return 0;
}