import java.util.*;

import javax.imageio.event.IIOReadWarningListener;
public class Solution{
	 public static int n;
     public static void main(String args[])
     {    
        Scanner take=new Scanner(System.in);
        int t=take.nextInt();
        int i,j;
        while(t--!=0)
        {
        	int n=take.nextInt();
        	int a[]=new int[n];
        	int v[]=new int[n];
        	for(i=0;i<n;i++) a[i]=take.nextInt();
        	int max=a[0];
        	int maxi=0;
        	for(i=0;i<n;i++) 
        	{
        		if(a[i]>max) {
        			max=a[i];
        			maxi=i;
        		}
        	}
        	System.out.print(max+" ");
        	v[maxi]=-1;
        	int gc=max;
        	for(i=0;i<n;i++)
        	{	int temp=-1;
        		for(j=0;j<n;j++)
        		{	if(v[i]!=-1)
        			if(gcd(gc,a[i])>temp)
        			{
        				temp=gcd(gc, a[i]);
        				maxi=i;
        			}
        		}
        		v[maxi]=-1;
        		System.out.print(a[maxi]+" ");
        		gc=gcd(a[maxi], gc);
        	}
        	System.out.println();
        }
     }
     public static int gcd(int a,int b)
     {
    	 if(a==0) return b;
    	 if(b==0) return a;
    	 if(a>b) return gcd(a%b, b);
    	 else return gcd(a, b%a);
     }
}
