import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codeforces {

    static int gcd(int a,int b)
    {
        if(a==0)
            return b;
        return gcd(b%a,a);
    }
    public static void main(String[] args) throws java.lang.Exception {
        /* your code goes here */
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(buf.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < t; i++) {
            int n=Integer.parseInt(buf.readLine());
            int arr[]=new int[n];
            int visited[]=new int[n];

            String st1[]=(buf.readLine()).split(" ");
            for(int j=0;j<n;j++)
                arr[j]=Integer.parseInt(st1[j]);
            Arrays.sort(arr);
            int max=arr[n-1];
            int ans[]=new int[n];
            ans[0]=max;
            max=0;
            int g=ans[0],m=-1,r=-1;
            sb.append(ans[0]+" ");
            visited[n-1]=-1;
            for(int j=1;j<n;j++)
            {
                for(int z=n-1;z>=0;z--)
                {
                    if(visited[z]!=-1) {
                        int val = gcd(g, arr[z]);
                        if (val >= max) {
                            max = val;
                            m = arr[z];
                            r = z;
                        }
                    }
                }
                ans[j]=m;
                visited[r]=-1;
                g=max;
                max=0;
                m=-1;
                r=-1;
                sb.append(ans[j]+" ");
            }
            sb.append("\n");
        }
        System.out.println(sb);
    }
}