import java.util.*;
import java.io.*;
/**
 *
 * @author alanl
 */
public class Main{
    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main(String[] args) throws IOException{
        int t = readInt();
        while(t-->0){
            int n = readInt();
            ArrayList<Integer>arr = new ArrayList(), ans = new ArrayList();
            for(int i = 0; i<n; i++){
                arr.add(readInt());
            }
            Collections.sort(arr, Collections.reverseOrder());
            ans.add(arr.get(0));
            arr.remove(0);
            for(int i = n-2; i>=0; i--){
                boolean flag = false;
                for(int j = 0; j<arr.size(); j++){
                    if(ans.get(ans.size()-1)%arr.get(j)==0){
                        flag = true;
                        ans.add(arr.get(j));
                        arr.remove(j);
                        break;
                    }
                }
                if(!flag){
                    ans.add(arr.get(0));
                    arr.remove(0);
                }
            }
            for(int i:ans)System.out.print(i+" ");
            System.out.println();
        }
    }
    static long gcd(long a, long b) {
        while(a!=0){
            long sub = a;
            a = b%a;
            b = sub;
        }
        return b;
    }
    static String next () throws IOException {
        while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(input.readLine().trim());
        return st.nextToken();
    }
    static long readLong () throws IOException {
        return Long.parseLong(next());
    }
    static int readInt () throws IOException {
        return Integer.parseInt(next());
    }
    static double readDouble () throws IOException {
        return Double.parseDouble(next());
    }
    static char readChar () throws IOException {
        return next().charAt(0);
    }
    static String readLine () throws IOException {
        return input.readLine().trim();
    }
    static void print(Object b) {
        System.out.print(b);
    }
    static void println(Object b) {
        System.out.println(b);
    }
    static void println() {
        System.out.println();
    }
    /* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
    // Did you read the bounds?
    // Did you make typos?
    // Are there edge cases (N=1?)
    // Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
    // Integer overflow?
    // DS reset properly between test cases?
    // Is using long longs causing TLE?
    // Are you using floating points?
    */
}
