#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define all(X) (X).begin(),(X).end()
#define ln "\n"
#define out cout
#define NON_TOGLIERE ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define VI vector<int>
#define pii pair<int,int>
#define PQ priority_queue
#define sz(v) ((int)v.size())
#define inf 1000000001
#define maxn 200010
using namespace std;
#if ONLINE_JUDGE
    #define in cin
#else
	ifstream in("input.txt");
#endif

ll n,i,Q,T,j,k,t,x,y,c[maxn];
VI v[maxn];
pii s[maxn];
int main(){
	NON_TOGLIERE
	in>>Q;
	for(T=1;T<=Q;T++){
		in>>n; ll tot=0,f=0;
		for(i=1;i<=n;i++){
			in>>s[i].fi;
			tot+=s[i].fi;
			v[i].clear();
		}
		for(i=0;i<n-1;i++){
			in>>x>>y;
			v[x].pb(y);
			v[y].pb(x);
		}
		for(i=1;i<=n;i++){
			s[i].se=sz(v[i])-1;
		}
		sort(s,s+n+1);
		f=tot;cout<<f<<" ";
		ll boh=n-1;
		for(i=n;i&&boh;i--){
			while(s[i].se>0&&boh){
				tot+=s[i].fi;
				cout<<tot<<" ";
				boh--;
				s[i].se--;
			}
		}cout<<ln;
	}
}

