import java.util.Scanner;

public class Main {
    static int calcgcd(int a,int b)
    {
        if(b==0)
            return a;
        else
            return calcgcd(a,a%b);
    }
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int t1=in.nextInt();
        while(t1-->0){
            int n=in.nextInt();
            int []arr=new int[n];
            int max=Integer.MIN_VALUE;
            int t=0;
            for(int i=0;i<n;i++){
                arr[i]=in.nextInt();
                if(arr[i]>max)
                {max=arr[i];
                 t=i;
                }
            }
            boolean b[]=new boolean[n];b[t]=true;
            System.out.print(max+" ");

            for(int a=0;a<n-1;a++){int gcd=1;t=-1;
                for(int i=0;i<n;i++){
                    if(!b[i]){
                        int g1=calcgcd(max,arr[i]);
                        if(g1>=gcd){
                            gcd=g1;
                            t=i;
                        }
                    }
                }
                b[t]=true;
                max=gcd;
                System.out.print(arr[t]+" ");
            }
            System.out.println();
        }
    }
}
