/*package whatever //do not write package name here */

import java.io.*;
import java.lang.*;
import java.util.*;
import java.lang.*;
public class GFG {
    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);
	    int t=sc.nextInt();
	    while(t-->0)
	    {
	        int n=sc.nextInt();
	        int v[]=new int[n];
	        int maxi=Integer.MIN_VALUE;
	        int index=0;
	        for(int i=0;i<n;i++)
	        {
	            v[i]=sc.nextInt();
	            if(v[i]>maxi)
	            {
	                index=i;
	                maxi=v[i];
	            }
	            
	        }
	        v[index]=-1;
	        int y=maxi;
	        System.out.print(maxi+" ");
	        ArrayList<Integer> arr=new ArrayList<Integer>();
	        for(int i=0;i<n;i++)
	        {
	            int maxii=Integer.MIN_VALUE;
	            int ele=0;
	            boolean flag=false;
	           for(int j=0;j<n;j++)
	           {
	               if(v[j]==-1)
	               continue;
	               y=gcd(maxi,v[j]);
	               if(y>maxii)
	               {
	                   flag=true;
	                   maxii=y;
	                   index=j;
	                   ele=v[index];
	               }
	               
	           }
	           if(flag)
	           {
	                v[index]=-1;
	                arr.add(ele);
	                maxi=maxii;
	                
	           }
	           
	        }
	        for(int x:arr)
	        System.out.print(x+" ");
	        System.out.println();
	    }
		
	}
}