Problem: Polycarp is an organizer of a Berland ICPC regional event. There are n universities in Berland numbered from 1 to n. Polycarp knows all competitive programmers in the region. There are n students: the i-th student is enrolled at a university u_i and has a programming skill s_i.

Polycarp has to decide on the rules now. In particular, the number of members in the team.

Polycarp knows that if he chooses the size of the team to be some integer k, each university will send their k strongest (with the highest programming skill s) students in the first team, the next k strongest students in the second team and so on. If there are fewer than k students left, then the team can't be formed. Note that there might be universities that send zero teams.

The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is 0.

Help Polycarp to find the strength of the region for each choice of k from 1 to n.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.

The first line of each testcase contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of universities and the number of students.

The second line of each testcase contains n integers u_1, u_2, ..., u_n (1 ≤ u_i ≤ n) — the university the i-th student is enrolled at.

The third line of each testcase contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 10^9) — the programming skill of the i-th student.

The sum of n over all testcases doesn't exceed 2 ⋅ 10^5.

Output

For each testcase print n integers: the strength of the region — the total skill of the members of the present teams — for each choice of team size k.

Example

Input


4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083


Output


29 28 26 19 0 0 0 
24907 20705 22805 9514 0 0 0 0 0 0 
43 43 43 32 38 43 
3083 

Note

In the first testcase the teams from each university for each k are: 

  * k=1: 
    * university 1: [6], [5], [5], [3]; 
    * university 2: [8], [1], [1]; 
  * k=2: 
    * university 1: [6, 5], [5, 3]; 
    * university 2: [8, 1]; 
  * k=3: 
    * university 1: [6, 5, 5]; 
    * university 2: [8, 1, 1]; 
  * k=4: 
    * university 1: [6, 5, 5, 3]; 

Solution (in CPP):

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

#define int long long
#define ull unsigned long long
#define N 20000001
#define endl "\n"

/*
vector <bool> prime(N + 1, true) ;
vector <ull> fac(N) ;
vector <ull> inverse_fac(N) ;


bool check_prime(int n){
	if(n == 1)
		return false ;
	if(n % 2 == 0)
		return false ;
	for(int i = 3; i <= sqrt(n); i += 2){
		if(n % i == 0)
			return false ;
	}
	return true ;
}

void SieveOfEratosthenes(int n) {
	prime[0] = false ;
	prime[1] = false ;
	for (int i = 2; i * i <= n; i++) {
		if (prime[i] == true) {
			for (int j = i * i; j <= n; j += i)
				prime[j] = false;
		}
	}
	return ;
}

void calc_fact(ull mod) {
	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = (fac[i - 1] * i) % mod;
}

ull mod_expo(ull a, ull n, ull mod) {
	ull res{1} ;
	a = a % mod;
	while (n) {
		if (n & 1)
			res = (res * a) % mod;
		n = n >> 1;
		a = (a * a) % mod ;
	}
	return res % mod;
}

ull modInverse(ull n, ull mod) {
	return mod_expo(n, mod - 2, mod);
}

void calc_inverse_fact(ull mod) {
	inverse_fac[N - 1] = modInverse(fac[N - 1], mod) ;
	for (int i = N - 2; i >= 0; i--) {
		inverse_fac[i] = (inverse_fac[i + 1] * (i + 1)) % mod ;
	}
}


ull nCr_mod_fermat1(ull n, ull r, ull mod) {
	if (n < r)
		return 0;
	if (r == 0)
		return 1;
	ull res{fac[n]} ;
	res = (res * modInverse(fac[r], mod)) % mod ;
	res = (res * modInverse(fac[n - r], mod)) % mod ;
	return res ;
}

ull nCr_mod_fermat2(ull n, ull r, ull mod) {
	if (n < r)
		return 0;
	if (r == 0)
		return 1;
	ull res{fac[n]} ;
	res = (res * inverse_fac[r]) % mod ;
	res = (res * inverse_fac[n - r]) % mod ;
	return res ;
}


int extended_gcd(int a, int b, int *x, int *y) {
	if (a == 0) {
		*x = 0;
		*y = 1;
		return b;
	}
	int x1{}, y1{} ;
	int gcd = extended_gcd(b % a, a, &x1, &y1);
	*x = y1 - (b / a) * x1;
	*y = x1;
	return gcd;
}


vector <int> find_next_greater_element(vector <int> &vec) {
	int n{} ;
	n = vec.size() ;
	vector <int> res(n, -1) ;
	stack <int> st{} ;
	st.push(n - 1);
	for (int i = n - 2; i >= 0; i--) {
		while (!st.empty() && vec[st.top()] <= vec[i])
			st.pop();
		if (!st.empty())
			res[i] = st.top() ;
		st.push(i);
	}
	return res ;
}

vector <int> find_prev_smaller_element(vector <int> &vec) {
	int n{} ;
	n = vec.size() ;
	vector <int> res(n, -1) ;
	stack <int> st{} ;
	st.push(0);
	for (int i = 1; i < n; i++) {
		while (!st.empty() && vec[st.top()] >= vec[i])
			st.pop();
		if (!st.empty())
			res[i] = st.top() ;
		st.push(i);
	}
	return res ;
}

struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

// user defined comp for sets etc.
struct comp {
	bool operator()(const pair <int, int> &p1, const pair <int, int> &p2) {
		if (p1.first != p2.first)
			return p1.first < p2.first ;
		return p1.second > p2.second ;
	}
} ;


#define INF 1e18


// Counting no of inversions using a segment tree
vector <int> st(400004) ;              // sum of a segment

void build_st(int si, int ss, int se, vector <int> &vis) {
	if (ss == se) {
		st[si] = vis[ss] ;
		return ;
	}
	int mid{} ;
	mid = (ss + (se - ss) / 2) ;
	build_st(2 * si, ss, mid, vis) ;
	build_st(2 * si + 1, mid + 1, se, vis) ;
	st[si] = st[2 * si] + st[2 * si + 1] ;
}

int query_st(int si, int ss, int se, int qs, int qe, vector <int> &vis) {
	if (qs > se || qe < ss)
		return 0 ;
	else if (qs <= ss && qe >= se)
		return st[si] ;
	int mid{} ;
	mid = ss + (se - ss) / 2 ;
	int l{}, r{} ;
	l = query_st(2 * si, ss, mid, qs, qe, vis) ;
	r = query_st(2 * si + 1, mid + 1, se, qs, qe, vis) ;
	return l + r ;
}

void point_update_st(int si, int ss, int se, int qi, vector <int> &vis) {
	if (ss == se) {
		st[si] = vis[se] ;
		return ;
	}
	int mid{} ;
	mid = ss + (se - ss) / 2 ;
	if (qi <= mid)
		point_update_st(2 * si, ss, mid, qi, vis) ;
	else
		point_update_st(2 * si + 1, mid + 1, se, qi, vis) ;
	st[si] = st[2 * si] + st[2 * si + 1] ;
}
*/

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin) ;

	freopen("output1.txt", "w", stdout) ;
#endif
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int t{} ;
	cin >> t ;
	while (t--) {
		int n{} ;
		cin >> n ;
		vector <int> vec1(n, 0) ;
		vector <int> vec2(n + 1, 0) ;
		for (int i = 0; i < n; i++)
			cin >> vec1[i] ;
		for (int i = 1; i <= n; i++)
			cin >> vec2[i] ;
		vector <vector <int>> vec(n + 1) ;
		for (int i = 0; i < n; i++) {
			int ui{} ;
			ui = vec1[i] ;
			vec[ui].push_back(vec2[i + 1]) ;
		}
		int max_sz{} ;
		for (int i = 1; i <= n; i++)
			sort(vec[i].begin(), vec[i].end(), greater <int>()) ;
		for (int i = 1; i <= n; i++) {
			max_sz = max(max_sz, (int)vec[i].size()) ;
			int sz{} ;
			sz = vec[i].size() ;
			for (int j = 1; j < sz; j++)
				vec[i][j] += vec[i][j - 1] ;
		}
		vector <int> ans(n, 0) ;
		for (int i = 1; i <= n; i++) {
			for (int k = 1; k <= vec[i].size(); k++) {
				int curr_sz{} ;
				curr_sz = vec[i].size() ;
				int idx{}, quo{}, rem{} ;
				quo = curr_sz / k ;
				idx = quo * k - 1 ;
				if (idx >= 0)
					ans[k - 1] += vec[i][idx] ;
			}
		}
		for (auto elem : ans)
			cout << elem << " " ;
		cout << endl ;
	}
	return 0 ;
}