#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
int cnt = 0;
int x[100005];
ll y[100005];
struct node 
{
    int data, c;
} e[maxn];
bool cmp(node a,node b)
{
    return a.data > b.data;
}
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        ll sum = 0;
        for (int i = 1; i <= n;i++)
        {
            cin >> e[i].data;
            sum += e[i].data;
        }
        for (int i = 1;i<n;i++)
        {
            int a, b;
            cin >> a >> b;
            e[a].c++;
            e[b].c++;
        }
        for (int i = 1; i <= n;i++)
        {
            e[i].c--;
        }
        cout << sum << " ";
        sort(e + 1, e + 1 + n, cmp);
        for (int i = 1; i <= n;i++)
        {
            if(e[i].c)
            {
                while(e[i].c)
                {
                    sum += e[i].data;
                    cout << sum << " ";
                    e[i].c--;
                }
            }
        }
        cout << endl;
    }
    return 0;
}
