import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Round_669D2P2 {
    static final FS sc = new FS();
    static final PrintWriter pw = new PrintWriter(System.out);
    static int gcd(int num1, int num2){
        while (num1 != num2) {
            if(num1 > num2)
                num1 = num1 - num2;
            else
                num2 = num2 - num1;
        }
        return num2;
    }
    public static void main(String[] args) {
        int t = sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            int[] a = sc.nextArray(n);
            Arrays.sort(a);
            StringBuilder sb = new StringBuilder();
            if(n==1){
                System.out.println(a[0]);
                continue;
            }
            else if(n==2){
                System.out.println(a[1]+" "+a[0]);
                continue;
            }
            int gcd = gcd(a[n-1],a[n-2]);

            //sb.append(a[n-1]+" ");
            int prevgcd = a[n-1];
            for(int i=n-2; i>=0; i--){
                int ind = i;
                int comp = Integer.MIN_VALUE;
                for(int j=i; j>=0; j--){
                    gcd = gcd(prevgcd, a[j]);
                    if(comp<gcd){
                        comp = gcd;
                        ind = j;
                    }
                    //System.out.println(ind+" "+gcd+" "+a[i]+" "+a[j]);
                }
                prevgcd = comp;
                int temp = a[i];
                a[i] = a[ind];
                a[ind] = temp;
            }
            for(int i=n-1; i>=0; i--){
                sb.append(a[i]+" ");
            }
            //System.out.println(Arrays.toString(a));
            System.out.println(sb.toString());
        }
    }

    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception ignored) {
                }
            }
            return st.nextToken();
        }

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

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

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

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