import java.util.*;
public class arr_sort2d___gcd___transpose//convert int to biginteger find gcd(inbuild) 
                                         //then conv. bigInteger to int
{
    public static void solve1(int a[][],int n)
    {
        int t[][]=new int[n][2];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<2;j++)
            {
                t[i][j]=a[j][i];
                //System.out.print(t[i][j]+"/");
            }
            //System.out.println();
        }
        Arrays.sort(t,new Comparator<int []>()
        {
            public int compare(int one[],int two[])
            {
                if(one[0]<two[0])
                    return 1;
                else
                    return -1;
            }
        });
        for(int i=0;i<2;i++)
        {
            for(int j=0;j<n;j++)
            {
                a[i][j]=t[j][i];
            }
        }
    }
    public static void solve(int a[][],int n)
    {
        int t[][]=new int[n][2];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<2;j++)
            {
                t[i][j]=a[j][i];
                //System.out.print(t[i][j]+"/");
            }
            //System.out.println();
        }
        Arrays.sort(t,new Comparator<int []>()
        {
            public int compare(int one[],int two[])
            {
                if(one[1]>two[1])
                    return 1;
                else
                    return -1;
            }
        });
        for(int i=0;i<2;i++)
        {
            for(int j=0;j<n;j++)
            {
                a[i][j]=t[j][i];
            }
        }
    }
    public static int gCD(int a,int b)
    {
        if(b==0)
            return a;
        else
        {
            return gCD(b,a%b);
        }
        //return a;
    }
    public static void gcd(int a[][],int max,int n)
    {
        int ori=max;
        for(int i=0; i<n ;i++)
        {
            
            {
                int ans=gCD(max,a[0][i]);
                if(a[0][i]!=ori)
                    a[1][i]=ans;
                max=ans;
            }
        }
        
    }
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t--!=0)
        {
            int n=sc.nextInt();
            int a[][]=new int[2][n];
            int max=0;
            for(int i=0;i<n;i++)
            {
                a[0][i]=sc.nextInt();
                if(a[0][i]>max)
                    max=a[0][i];
                a[1][i]=0;
            }
            System.out.print(max+" ");
            solve1(a,n);
            gcd(a,max,n);
            solve(a,n);/*
            for(int i=0;i<2;i++)
            {
                for(int j=0;j<n;j++)
                    System.out.print(a[i][j]+"||");
                System.out.println();
            }
            */
            for(int i=n-1;i>=0 ;i--)
            {
                if(a[0][i]!=max)
                    System.out.print(a[0][i]+" ");
            }
            System.out.println();
        }
    }
}