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

typedef long long ll;   

#define endl "\n"
#define F first
#define S second
#define test int t;cin>>t;while(t--)


int main()
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    test{

        ll n;
        cin>>n; 

        ll ar[n], sm = 0; 
        for(ll i=0; i<n; i++){
            cin>>ar[i]; 
            sm += ar[i]; 
        }

        vector<ll> adj[n+1]; 
        for(ll i=0; i<n-1; i++){
            ll u, v; 
            cin>>u>>v; 

            adj[u].push_back(v); 
            adj[v].push_back(u); 
        }

        priority_queue<pair<ll, ll>> val_deg; 
        for(ll i=1; i<=n; i++){
            ll deg = adj[i].size(); 
            if(deg>1){
                val_deg.push({ar[i-1], deg});
                // cout<<i<<" "<<ar[i]<<" "<<deg<<endl;
            }

        }

        cout<<sm<<" "; 
        while(!val_deg.empty()){
            pair<ll, ll> t = val_deg.top(); 
            val_deg.pop(); 

            ll r = t.second; 
            while(--r){
                sm += t.first; 
                cout<<sm<<" "; 
            }

        }


        cout<<endl;

    }

    return 0; 

}