#include<bits/stdc++.h>
using namespace std;
 
#define LL signed long long
#define D double
#define LD long double
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<LL,LL>
#define PLI pair<LL, int>
#define PIL pair<int, LL>
#define PSI pari<string, int>
#define PSS pair<string, string>
#define PIS pair<int, string>
#define SPLL pair<sLL, sLL>
#define pb(x) push_back(x)
#define pp() pop_back()
#define IN(x) insert(x)
#define VI vector<int>
#define VLL vector<LL>
#define VD vector<double>
#define VS vector<string>
#define VC vector<char>
#define VB vector<bool>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define VVI vector<VI>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mem(x, y) memset(x, y, sizeof(x))
#define SUM(sum, v) for(auto& i : v) sum += i;
int dx[] {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int const N = 1e5 + 10;


void solve()
{
	int n; cin>>n; VI v[n+5];
	int deg[n+5]; mem(deg, 0); bool vis[n+5]; mem(vis, 0);
	LL we[N+5];
	for(int i = 1; i <= n; i++) cin>>we[i];
	int a, b;
	for(int i = 1; i < n; i++){
		cin>>a>>b;
		deg[a]++;
		deg[b]++;
	}
	LL sum = 0; for(int i = 1; i <= n; i++) sum += we[i];
	VI sq;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < deg[i] - 1; j++) sq.pb(we[i]);
	}
	sort(sq.rbegin(), sq.rend());
	cout<<sum<<" ";
	for(auto i : sq) {
		sum += i;
		cout<<sum<<" ";
	}
	cout<<endl;
}

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

   	int T = 1; 
   	cin>>T;
 	
 	while(T--)
 	{
 		solve();
 	}
 }  
