
import java.awt.Desktop;

import java.io.BufferedReader;


import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;



public  class codechef3 {
static class comp implements Comparator<Integer>
{

	@Override
	public int compare(Integer o1, Integer o2) {
		if(Math.abs(o1)>Math.abs(o2))
			return -1;
		else return 1;
	
	}

	
	}
	   

		 static class FastReader
		    {BufferedReader br; 
		        StringTokenizer st; 
		 public FastReader() 
		        {  br = new BufferedReader(new
		                     InputStreamReader(System.in)); 
		        } 
		  
		       String next() 
		        { 
		            while (st == null || !st.hasMoreElements()) 
		            { 
		                try
		                { 
		                    st = new StringTokenizer(br.readLine()); 
		                } 
		                catch (IOException  e) 
		                { 
		                    e.printStackTrace(); 
		                } 
		            } 
		            return st.nextToken(); 
		        } 
		  
		        int nextInt() 
		        { 
		            return Integer.parseInt(next()); 
		        } 
		  
		        long nextLong() 
		        { 
		            return Long.parseLong(next()); 
		        } 
		  
		        double nextDouble() 
		        { 
		            return Double.parseDouble(next()); 
		        } 
		  
		        String nextLine() 
		        { 
		            String str = ""; 
		            try
		            { 
		                str = br.readLine(); 
		            } 
		            catch (IOException e) 
		            { 
		                e.printStackTrace(); 
		            } 
		            return str; 
		        } 
		    } 
		 public static boolean check(long n,int d)
		 {
			 while(n>0)
			 {
				long r=n%10;
				 if(r==d)
					 return true;
				 n=n/10;
			 }
			 return false;
		 }
		 public static int gcd(int a, int b)
		    {
		      if (b == 0)
		        return a;
		      return gcd(b, a % b); 
		    }
		    
		    public static void main(String[] args) 
		    {
		    	FastReader s=new FastReader();
		    	int t=s.nextInt();
		    	while(t-->0)
		    	{
		    	int n=s.nextInt();
		    	int[] a=new int[n];
		    	
		    	
		    	for(int i=0;i<n;i++)
		    		a[i]=s.nextInt();
		    	
		    	Arrays.sort(a);
		    	int re=0;
		    	ArrayList<Integer> l=new ArrayList<>();
		    	
		    	
		    	for(int i=n-1;i>=0;i--)
		    	{
		    		
		    		
		    		int add=i;
		    		int max=Integer.MIN_VALUE;
		    		
		    		for(int j=0;j<n;j++)
		    		{
		    			if(a[j]==-1)
		    				continue;
		    			int temp=gcd(re,a[j]);
		    			
		    			if(max>temp)
		    			{
		    				max=temp;
		    				add=j;
		    			}
		    			
		    		}
		    		
		    		int last=a[add];
		    		re=gcd(re,last);
		    		l.add(last);
		    		a[add]=-1;
		    		
		    		
		    	}
		    	
		    	for(int i=0;i<l.size();i++)
		    		System.out.print(l.get(i)+" ");
		    	System.out.println();
		    	
		    	
		    	
		    	
		    	
		    	
		    	
		    
		    }





}}