#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500000];
bool mohir(ll a,ll b)
{
    return a>b;
}
int main()
{
    ll test,i,j;
    cin>>test;
    while(test--)
    {
        ll s=0;
        ll n;
        cin>>n;
        for(i=1; i<=n; i++)
        {
            cin>>ar[i];
            s+=ar[i];
        }
        map<ll,ll>mp;
        for(i=1; i<n; i++)
        {
            ll a,b;
            cin>>a>>b;
            mp[a]++;
            mp[b]++;
        }
        vector<ll>vc;
        for(i=1; i<=n; i++)
        {
            for(j=2; j<=mp[i]; j++)
            {
                vc.push_back(ar[i]);
            }
        }
        sort(vc.begin(),vc.end(),mohir);
        cout<<s<<" ";ll c=0;
        for(i=2;i<n;i++)
        {
            c+=vc[i-2];
            cout<<s+c<<" ";
        }cout<<endl;
    }
}
