import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void  main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		StringBuilder sb=new StringBuilder();
		
		int t=s.nextInt();
		
		for(int i=0;i<t;i++)
		{
			int n=s.nextInt();
			
			Integer[] arr=new Integer[n];
			
			for(int j=0;j<n;j++)
			{
				arr[j]=s.nextInt();
			}
			
			Arrays.sort(arr);
			int[] brr=new int[n];
			
			sb.append(arr[n-1]+" ");
			brr[n-1]=1;
			
			int curr=arr[n-1];
			
			int count=1;
			
			while(count!=n)
			{
				int max=0;
				int index=-1;
				
				for(int j=0;j<n;j++)
				{
					if(brr[j]==0)
					{
						int gcd=gcd(curr,arr[j]);
						
						if(gcd>max)
						{
							max=gcd;
							index=j;
						}
					}
				}
				
				sb.append(arr[index]+" ");
				brr[index]=1;
				curr=gcd(curr,arr[index]);
				count++;
			}
			
			sb.append("\n");
			
		}
		
		System.out.println(sb);
		
	}
	
	public static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 
	
}