
/*
 932 520 620 590 142 218 858 757 157 353 
 */
import java.io.*;
import java.util.*;
 
public class B 
{		
	public static void main(String[] args)throws IOException 
	{	
		FastReader f=new FastReader();
		StringBuffer sb = new StringBuffer();

		int test=f.nextInt();
		while(test-->0)
		{
			int n=f.nextInt();
			int a[]=new int[n];
			
			List<Integer> ans=new ArrayList<>();
			int max=0;
			Map<Integer,Integer> map=new HashMap<>();
			for(int i=0;i<n;i++)
			{
				a[i]=f.nextInt();
				max=Math.max(max,a[i]);
				map.put(a[i],map.getOrDefault(a[i],0));
			}
			ans.add(max);
			int v=map.get(max);
			v--;
			if(v>0) map.put(max,v);
			else map.remove(max);
			
			while(!map.isEmpty())
			{	
				int x=max;
				max=0;
				int idx=0;
				for(int key : map.keySet())
				{	
					if(gcd(x,key)>max)
					{
						max=gcd(x,key);
						idx=key;
					}
				}
				ans.add(idx);
				
				v=map.get(idx);
				v--;
				if(v>0) map.put(idx,v);
				else map.remove(idx);
			}
			
			for(int i:ans)
				sb.append(i+" ");
			sb.append("\n");
		}
		System.out.println(sb);
	}
	
	public static int gcd(int a, int b) {
		if (a == 0)
			return b;

		return gcd(b % a, a);
	}
	
	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; 
	    } 
	} 
}