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 JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.text.*;

public class CF_1519_C{
    //SOLUTION BEGIN
    Random R = new Random();
    int[] spf;
    void pre() throws Exception{spf = spf((int)200005);}
    void solve(int TC) throws Exception{
        int N = ni();
        int[] U = new int[N], S = new int[N], T = new int[N];
        for(int i = 0; i< N; i++)T[i] = U[i] = ni();
        for(int i = 0; i< N; i++)S[i] = ni();
        shuffle(T);
        Arrays.sort(T);
        int cnt = 1;
        for(int i = 1; i< T.length; i++)if(T[i] != T[cnt-1])T[cnt++] = T[i];
        for(int i = 0; i< N; i++)U[i] = Arrays.binarySearch(T, 0, cnt, U[i]);

        int[] sz = new int[cnt];
        for(int x:U)sz[x]++;
        long[][] lists = new long[cnt][];
        for(int i = 0; i< cnt; i++)lists[i] = new long[sz[i]];
        for(int i = 0; i< N; i++)lists[U[i]][--sz[U[i]]] = S[i];
        for(int i = 0; i< cnt; i++){
            long[] sum = new long[lists[i].length];
            shuffle(lists[i]);
            Arrays.sort(lists[i]);
            reverse(lists[i]);
            for(int j = 0; j< lists[i].length; j++)sum[j] = (j == 0?0:sum[j-1])+lists[i][j];
            lists[i] = sum;
        }
        Arrays.sort(lists, (long[] i1, long[] i2) -> Integer.compare(i2.length, i1.length));

        long[] ans = new long[1+N];
        for(int k = 1; k<= N; k++){
            long o = 0;
            for(int i = 0; i< lists.length && lists[i].length >= k; i++){
                int len = ((lists[i].length)/k)*k;
                o += lists[i][len-1];
            }
            p(o);
        }
        pn("");

    }
    void reverse(int[] T){
        for(int i = 0, j = T.length-1; i< j; i++, j--){
            int tmp = T[i];
            T[i] = T[j];
            T[j] = tmp;
        }
    }
    void reverse(long[] T){
        for(int i = 0, j = T.length-1; i< j; i++, j--){
            long tmp = T[i];
            T[i] = T[j];
            T[j] = tmp;
        }
    }
    void shuffle(int[] T){
        int N = T.length;
        for(int i = 0; i< N; i++){
            int u = R.nextInt(N), v = R.nextInt(N);
            int tmp = T[u];
            T[u] = T[v];
            T[v] = tmp;
        }
    }
    void shuffle(long[] T){
        int N = T.length;
        for(int i = 0; i< N; i++){
            int u = R.nextInt(N), v = R.nextInt(N);
            long tmp = T[u];
            T[u] = T[v];
            T[v] = tmp;
        }
    }
    int[] spf(int max){
        int[] spf = new int[1+max];
        for(int i = 2; i<= max; i++)
            if(spf[i] == 0)
                for(int j = i; j <= max; j += i)
                    if(spf[j] == 0)
                        spf[j] = i;
        return spf;
    }
    int[] factors(int[] spf, int x){
        int[] factor = new int[]{1};
        while(x > 1){
            int p = spf[x], cnt = 0;
            for(;x%p == 0; x/= p)cnt++;
            int[] tmp = Arrays.copyOf(factor, (1+cnt)*factor.length);
            for(int pw = 1, cur = p; pw <= cnt; pw++, cur *= p)
                for(int i = 0; i< factor.length; i++)
                    tmp[pw*factor.length+i] = factor[i]*cur;
            factor = tmp;
        }
        return factor;
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}
    final long IINF = (long)1e17;
    final int INF = (int)1e9+2;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = true, memory = true, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        long ct = System.currentTimeMillis();
        if (fileIO) {
            in = new FastReader("");
            out = new PrintWriter("");
        } else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = multipleTC? ni():1;
        pre();
        for (int t = 1; t <= T; t++) solve(t);
        out.flush();
        out.close();
        System.err.println(System.currentTimeMillis() - ct);
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new CF_1519_C().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 28).start();
        else new CF_1519_C().run();
    }
    int[][] make(int n, int e, int[] from, int[] to, boolean f){
        int[][] g = new int[n][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = to[i];
            if(f)g[to[i]][--cnt[to[i]]] = from[i];
        }
        return g;
    }
    int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){
        int[][][] g = new int[n][][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0};
            if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1};
        }
        return g;
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object... o){for(Object oo:o)out.print(oo+" ");}
    void pn(Object... o){for(int i = 0; i< o.length; i++)out.print(o[i]+(i+1 < o.length?" ":"\n"));}
    void pni(Object... o){for(Object oo:o)out.print(oo+" ");out.println();out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str;
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}