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.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Run {
    static final long mod = (long) 1e9 + 7;
    static InputReader in = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static long inf = (long) -1e8;
    static long ss = 0;
    static int MAX_N = (int) 1e8 + 9;

    public static void main(String args[]) {

        int t = 1;
        t = in.nextInt();
        for (int i = 1; i <= t; i++) {
            solve();
        }
        pw.flush();
        pw.close();
    }

    private static void solve() {
        int n = in.nextInt();
        ArrayList[] t = new ArrayList[n + 1];
        long[] s = new long[n + 1];
        int[] u = new int[n + 1];
        for (int i = 0; i < n; i++) {
            u[i + 1] = in.nextInt();
        }
        for (int i = 0; i < n; i++) {
            s[i + 1] = in.nextLong();
            if (t[u[i + 1]] == null) {
                t[u[i + 1]] = new ArrayList<Long>();
            }
            t[u[i + 1]].add(s[i + 1]);
        }
        long[] ans = new long[n + 1];

        for (int i = 0; i < n; i++) {
            ArrayList<Long> ty = t[i + 1];
            if (ty == null) continue;
            Collections.sort(ty);
            long[] ar = new long[ty.size() + 1];
            ar[0] = 0L;
            for (int j = 1; j < ar.length; j++) {
                ar[j] = ar[j-1] + ty.get(j - 1);
//                System.out.print(ar[j] + " ");
            }
//            System.out.println();
            int ll = ar.length-1;
            for (int j = 1; j < ar.length; j++) {
                ans[j] += ar[ll] - ar[ll % j];
            }

        }

        for (int i = 0; i < n; i++) {
            System.out.print(ans[i + 1] + " ");
        }
        System.out.println();

//1
//7
//1 2 1 2 1 2 1
//6 8 3 1 5 1 5
    }

    private static long add(long a, long b, long m) {
        return ((a % m) + (b % m)) % m;
    }

    private static void dfs(Set<Integer>[] rev, boolean[] vis, int v) {
        vis[v] = true;
        for (int u : rev[v]) {
            if (vis[u]) continue;
            dfs(rev, vis, u);
        }

    }

    private static void topSort(ArrayList<Integer> top, ArrayList<Integer>[] g, int v, boolean[] vis) {
        vis[v] = true;
        for (int u : g[v]) {
            if (vis[u]) continue;
            topSort(top, g, u, vis);
        }
        top.add(v);
    }

    public static long gcd(long a, long b) {
        if (b != 0)
            return gcd(b, a % b);
        else
            return a;
    }


    static long maxSubArraySum(ArrayList<Long> a) {
        int size = a.size();
        long max_so_far = Integer.MIN_VALUE, max_ending_here = 0;

        for (int i = 0; i < size; i++) {
            max_ending_here = max_ending_here + a.get(i);

            if (max_so_far < max_ending_here)
                max_so_far = max_ending_here;
            if (max_ending_here < 0) {
                max_ending_here = 0;
            }
        }
        return Math.max(0l, max_so_far);
    }

    private static long ncr(long n, long k, long[] fact) {
        if (n < k) return 0;
        long ret = fact[(int) n];
        ret = (ret * pow(fact[(int) (n - k)], mod - 2, mod)) % mod;
        ret = (ret * pow(fact[(int) (k)], mod - 2, mod)) % mod;

        return ret;

    }

    private static long pow(long a, long b, long mod) {
        if (b == 0) return 1;
        if (b == 1) return a % mod;
        long t = pow(a, b / 2, mod);
        t = (t * t) % mod;
        if (b % 2 != 0) {
            t = (t * a) % mod;
        }
        return t;
    }

    private static int[] bfs(ArrayList<Integer>[] g, int a, int n) {
        int dist[] = new int[n + 1];
        for (int i = 0; i < n + 1; i++) {
            dist[i] = n + 10;
        }
        Queue<Integer> q = new LinkedList<>();
        boolean vis[] = new boolean[n + 1];
        dist[a] = 0;
        q.add(a);
        while (!q.isEmpty()) {
            int p = q.poll();
            if (vis[p] == true) {
                continue;
            }
            vis[p] = true;
            for (Integer i : g[p]) {
                if (!vis[i]) {
                    dist[i] = Integer.min(dist[i], dist[p] + 1);
                    q.add(i);
                }
            }
        }
        return dist;
    }

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }


}