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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.stream.Collectors;


/*
 * @author: Ramanqul
 * */
public class Main {
    private static final double EPS = .000000001;

    private static int findLower(long arr[], long x) {
        int l = -1, r = arr.length;

        while (r > l+1) {
            int mid = (l+r)/2;

            if (arr[mid] >= x) {
                r = mid;
            } else {
                l = mid;
            }
        }

        return r;
    }

    private static int binarySearch(Integer arr[][], int arrIdx, int key) {
        int l = 0, r = arr.length-1;

        while (l<=r) {
            int m = (l+r)/2;
            if (arr[m][arrIdx] < key) {
                l = m + 1;
            } else if (arr[m][arrIdx] > key) {
                r = m - 1;
            } else {
                return m;
            }
        }

        return -1;
    }

    private static int findUpper(int arr[], int x) {
        int l = -1, r = arr.length;

        while (r > l+1) {
            int mid = (l+r)/2;

            if (arr[mid] < x) {
                l = mid;
            } else {
                r = mid;
            }
        }

        return r;
    }

    private static boolean USE_TEST_CASES = true;

    private static void swap(List<Integer> list, int i, int j) {
        int t = list.get(i);
        list.set(i, list.get(j));
        list.set(j, t);
    }

    private static int sum(List<Integer> list, int ... indices) {
        int sum = 0;
        for (int i: indices) {
            sum += Math.abs(list.get(i));
        }
        return sum;
    }

    private static int prefixSum(int p[], int start, int end) {
        if (start == 0) {
            return p[end];
        }

        return p[end] - p[start-1];
    }

    private static boolean isChar(char arr[], char c, int index, int count) {
        return arr[index] == c && count > 0;
    }


    private static boolean isPal(String s) {
        for (int i=0;i<s.length()/2;i++) {
            if (s.charAt(i) != s.charAt(s.length()-i-1)) {
                return false;
            }
        }

        return true;
    }

    private static long calcSum(List<Long> prefix, int n) {
        if (prefix.size() < n) {
            return 0;
        }

        int mod = prefix.size() % n;

        if (mod == 0) {
            return prefix.get(prefix.size()-1);
        } else {
            return prefix.get(prefix.size()-mod-1);
        }
    }

    private static void solve(final int testCase, MyScanner in, PrintWriter out) {
        int n =in.nextInt();
        int u[] = new int[n];
        H.readArray(in, u, n);
        Map<Integer, Map<Integer, Integer>> data = new HashMap<>();

        for (int i=0;i<n;i++) {
            int x = in.nextInt();

            Map<Integer, Integer> map = data.get(u[i]);

            if (map == null) {
                map = new TreeMap<>(Collections.reverseOrder());
                data.put(u[i], map);
            }

            map.put(x, map.getOrDefault(x, 0) + 1);
        }

        Map<Integer, List<Long>> sortedData = new HashMap<>();

        for (Integer ukey: data.keySet()) {
            Map<Integer, Integer> map = data.get(ukey);

            List<Long> prefix = new ArrayList<>();

            for (int key: map.keySet()) {
                for (int i=0;i<map.get(key);i++) {
                    prefix.add(Long.valueOf(key));
                }
            }

            for (int j = 1; j < prefix.size(); j++) {
                prefix.set(j, prefix.get(j) + prefix.get(j - 1));
            }

            sortedData.put(ukey, prefix);
        }

        List<Long> sums = new ArrayList<>(n);

        for (int i=0;i<n;i++) {
            sums.add(0L);
        }

        Queue<List<Long>> queue1 = new LinkedList<>();
        Queue<List<Long>> queue2 = new LinkedList<>();

        for (Integer ukey: sortedData.keySet()) {
            queue1.add(sortedData.get(ukey));
        }

        for (int i=1;i<=n;i++) {

            while (!queue1.isEmpty()) {
                List<Long> prefix = queue1.poll();

                if (prefix.size() < i) {
                    continue;
                }

                sums.set(i-1, sums.get(i-1) + calcSum(prefix, i));

                queue2.add(prefix);
            }

            queue1 = queue2;
            queue2 = new LinkedList<>();
        }

        for (Long val: sums) {
            out.print(val + " ");
        }
        out.println();

    }

    private static void generateInput(String fileName) throws IOException {
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream(fileName)));

        writer.println(1);
        final int n = 200_000;
        Random rnd = new Random();
        writer.println(n);

        for (int i=0;i<n;i++) {
            writer.print(rnd.nextInt(1+100));
            writer.print(" ");
        }

        writer.close();
    }

    public static void main(String[] args) throws IOException {
//        String fileName = "sample.in";

//        generateInput(fileName);

        MyScanner sc = new MyScanner();//new BufferedInputStream(new FileInputStream(fileName)));

        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = 1;

        if (USE_TEST_CASES) {
            t = sc.nextInt();
        }

        for (int i=0;i<t;i++) {
            solve(i, sc, out);
        }

        out.close();
    }

    private static class Pair<A,B> {
        public A first;
        public B second;
        public Pair(A first, B second) {
            this.first = first;
            this.second = second;
        }
    }

    private static class Triple<A,B,C> {
        public A first;
        public B second;
        public C third;

        public Triple(A first, B second, C third) {
            this.first = first;
            this.second = second;
            this.third = third;
        }
    }

    private static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode() {}
        public TreeNode(int val) {
            this.val = val;
        }
    }

    private static class H {
        public static void readArray(MyScanner in, int a[], int n) {
            for (int i=0;i<n;i++) {
                a[i] = in.nextInt();
            }
        }

        public static boolean isUnique(int ... nums) {
            Set<Integer> s = new HashSet<>();
            for (int i:nums) {
                if (s.contains(i)) {
                    return false;
                }
                s.add(i);
            }

            return true;
        }


        public static Pair<Integer, Integer>[] readIntPairs(MyScanner in, int n) {
            Pair[] pairs = new Pair[n];
            for (int i=0;i<n;i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                pairs[i] = new Pair<Integer, Integer>(x, y);
            }

            return pairs;
        }

        public static List<Integer> dfs(int start, List<Integer>[] adj) {
            boolean v[] = new boolean[adj.length+1];

            List<Integer> res = new ArrayList<>();

            Stack<Integer> st = new Stack<>();

            st.push(start);

            while (!st.isEmpty()) {
                int x = st.pop();
                if (!v[x]) {
                    res.add(x);
                    boolean allVisited = true;
                    for (int e: adj[x]) {
                        if (!v[e]) {
                            st.push(e);
                            allVisited = false;
                        }
                    }

                    if (allVisited) {
                        break;
                    }

                    v[x] = true;
                } else {
                    break;
                }
            }

            return res;
        }

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

            return gcd(b%a, a);
        }

        public static long lcm(long a, long b) {
            return (a * b) / gcd(a,b);
        }
    }

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public MyScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}