/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t-->0){
		    int n=Integer.parseInt(br.readLine());
		    String ss[]=br.readLine().split(" ");
		    LinkedList<Integer> l=new LinkedList<>();
		    LinkedList<Integer> ll=new LinkedList<>();
		    int sum=0;
		    for(int i=0;i<n;++i){
		        ll.add(Integer.parseInt(ss[i]));
		    }
		  //  Collections.sort(ll);
		  int xx=Collections.max(ll);
		    l.add(xx);
		    ll.remove(new Integer(xx));
		    for(int j=0;j<n-1;++j){
    		    int max=1;
    		    int ans=0;
    		    for(int i=0;i<ll.size();++i){
    		        int nn=gcd(ll.get(i),l.get(l.size()-1));
    		      //  System.out.print(nn+" ");
    		        if(nn>max){
    		            max=nn;
    		            ans=i;
    		        }
    		        
    		    }
    		    l.add(ll.get(ans));
    		    ll.remove(ans);
		    }   
		   for(int i:l)System.out.print(i+" ");
		    System.out.println();
		}
	}
}
