#include<bits/stdc++.h>
using namespace std;
#define  pb    push_back
#define  mp    make_pair
#define  fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define  FOR(i,j,k,in)  for(int i=j;i<=k;i+=in)
#define  RFOR(i,j,k,dc) for(int i=j;i>=k;i-=dc)
#define  ff  first
#define  ss  second
#define  T   int t;cin>>t;while(t--)
#define  mem(a,b)  memset(a,(b),sizeof(a))
#define  all(c)   c.begin(),c.end()
#define  rall(c)  c.rbegin(),c.rend()
#define  FORIT(it,m)  for(it=m.begin();it!=m.end();it++)
#define  mod  1000000007
#define  maxin  INT_MAX
#define  minin  INT_MIN
#define  sz(cnt) (int)cnt.size()
#define  in(c,x)     c.find(x)!=c.end()
#define  bits  __builtin_popcount
#define  gcd   __gcd
typedef  long long int ll;
typedef  vector<ll>vi;
typedef  vector<string>vs;
typedef  map<ll,ll>mpii;
typedef  map<char,ll>mpci;
typedef  set<ll>sti;
typedef  multiset<ll>msti;
typedef  multimap<ll,ll>mmpii;
typedef  pair<ll,ll>pii;
ll power(ll a,ll b,ll m){
	ll res = 1;
	while(b>0){
		if(b%2==1){
		res = (res%m * a%m)%m;
		}
 
		a = (a%m * a%m)%m;
		b/=2;	
	}
	return res;
}
//********************THE END OF TEMPLATES*******************//

int main(){
	fast;
	
	T{
		ll n;
		cin>>n;

		vi v(n+1);

		ll s=0;
		FOR(i,1,n,1){
			cin>>v[i];
			s+=v[i];
		}

		ll x,y;

		vi deg(n+1);

		FOR(i,1,n-1,1){
			cin>>x>>y;

			deg[x]++;deg[y]++;
		}

		vi seq;

		FOR(i,1,n,1){
			FOR(j,1,deg[i]-1,1){
				seq.pb(v[i]);
			}
		}

		seq.pb(0);
		sort(rall(seq));

		for(auto &i : seq){
			cout<<s<<" ";
			s+=i;
		}

		cout<<endl;
	}
	return 0;
}
