import java.util.*;
import java.io.*;
public class P3{
    public static int gcd(int a,int b)
    {
            if(b==0)
            return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
                int t=sc.nextInt();
                while (t-->0) {
                    int n=sc.nextInt();
                    int max=0;
                    int[] arr=new int[n];
                    boolean check[]=new boolean[n];
                    int pos=0;
                    for(int i=0;i<n;i++){
                     arr[i]=sc.nextInt();
                     max=(int)Math.max(max,arr[i]);
                     if(max==arr[i]){pos=i;}
                    }
                    System.out.print(max+" ");
                    check[pos]=true;
                    int maxgcd=0,pos1=pos;
                    int c=1;
                    while(c<n){
                     pos=pos1;
                     check[pos]=true;
                     maxgcd=0;
                    for(int i=0;i<n;i++)
                    {
                        if(!check[i])   
                        {
                            int k=gcd(arr[i],max);
                            if(k>maxgcd){maxgcd=k;pos1=i;}
                        }
                    }
                        System.out.print(arr[pos1]+" ");
                        max=arr[pos1];c++;
                       
                    }
                    System.out.println();
                }
    }
}                   