import java.util.*;
import java.io.*;
public class Main
{
    public static int gcd(int a,int b)
    {
        if(a>b)
        return gcd(b,a);
        if(b%a==0)
        return a;
        return gcd(b%a,a);
    }
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int testCases=Integer.parseInt(br.readLine());
        while(testCases-->0)
        {
            int n=Integer.parseInt(br.readLine());
            String str[]=br.readLine().split(" ");
            int arr[]=new int[n];
            for(int i=0;i<n;i++)
            arr[i]=Integer.parseInt(str[i]);
            Arrays.sort(arr);
            int ans[]=new int[n];
            ans[0]=arr[n-1];
            int tp=n-2;
            while(tp>=0&&arr[tp]==arr[n-1])
            ans[n-1-tp]=arr[tp--];
            while(tp>=0)
            {
                int mx=0,ind=tp;;
                for(int i=tp;i>=0;i--)
                {
                    int gc=gcd(arr[i],arr[tp+1]);
                    if(mx<gc)
                    {
                        mx=gc;
                        ind=i;
                    }
                }
                int temp=arr[tp];
                arr[tp]=arr[ind];
                arr[ind]=temp;
                ans[n-1-tp]=arr[tp];
                tp--;
            }
            for(int i=0;i<n;i++)
            pw.print(ans[i]+" ");
            pw.println();
        }
        pw.flush();
        pw.close();
    }
}