import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public final class CF
{
    public static int gcd(int a,int b)
    {
        if(b==0)
            return a;
        return gcd(b,a%b);
    }
    public static void main(String[]args)throws IOException
    {
        FastReader ob=new FastReader();
        int t=ob.nextInt();
        StringBuffer sb=new StringBuffer();
        while(t-->0)
        {
            int n=ob.nextInt();
            int a[]=new int[n];
            int gcd=0,pos=-1;
            TreeSet<Integer> ts=new TreeSet<>();
            for (int i = 0; i < a.length; i++)
            {
                a[i]=ob.nextInt();
                if(gcd<a[i])
                {
                    gcd=a[i];
                    pos=i;
                }
            }
            Arrays.sort(a);
            ts.add(n-1);
            ArrayList<Integer> ans=new ArrayList<>();
            ans.add(gcd);
            for(int k=1;k<n;k++)
            {
                int max=0;pos=-1;
                for(int i=0;i<n;i++)
                {
                    int x=gcd(gcd, a[i]);
                    if(!ts.contains(i)&&x>max)
                    {
                        max=x;
                        pos=i;
                    }
                }
                ts.add(pos);
                ans.add(a[pos]);
                gcd=max;
            }
            for(int i=0;i<ans.size();i++)
            sb.append(ans.get(i)+" ");
            sb.append("\n");
        }
        System.out.println(sb);
    }
}
class FastReader {
    BufferedReader br;
    StringTokenizer st;
    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e)  {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    public String nextLine()
    {
        String s="";
        try {
        s=br.readLine();
        } catch (IOException e)  {
                e.printStackTrace();
            }
        return s;
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}