//created by Whiplash99
import java.io.*;
import java.util.*;
public class B
{
    private static int _gcd(int a, int b){return a==0?b:_gcd(b%a,a);}
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,j,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while (T-->0)
        {
            N=Integer.parseInt(br.readLine().trim());
            String[] s=br.readLine().trim().split(" ");
            int a[]=new int[N];
            for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

            int max=0,pos=-1;
            for(i=0;i<N;i++)
            {
                if(max<a[i])
                {
                    max=a[i];
                    pos=i;
                }
            }

            sb.append(max).append(" ");

            for(i=1;i<N;i++)
            {
                int gcd=max;
                a[pos]=-1; pos=-1; max=0;

                for(j=0;j<N;j++)
                {
                    if(a[j]==-1) continue;
                    int tmp=_gcd(gcd,a[j]);
                    if(tmp>max)
                    {
                        max=tmp;
                        pos=j;
                    }
                }
                sb.append(a[pos]).append(" ");
            }
            sb.append("\n");
        }
        System.out.println(sb);
    }
}