import java.util.*;
import java.io.*;
public class EdB {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());
 		for(int i = 0;i<t;i++){
//	 		String input1 = bf.readLine().trim();
//	 		String input2 = bf.readLine().trim();
	 		int n = Integer.parseInt(bf.readLine());
	 		ArrayList<Integer> array = new ArrayList<Integer>();
	 		StringTokenizer st2 = new StringTokenizer(bf.readLine());
	 		for(int j=0;j<n;j++){
	 			array.add(Integer.parseInt(st2.nextToken()));
	 		}
	 		Collections.sort(array);
	 		Set<Integer> seen = new HashSet<Integer>();
	 		seen.add(array.size()-1);
	 		
	 		int gcd = array.get(array.size()-1);
	 		
	 		out.print(array.get(array.size()-1) + " ");
	 		for(int j = 0;j<n-1;j++){
	 			int maxgcd = 0;
	 			int maxindex = 0;
	 			for(int k=0;k<n;k++){
	 				int tempgcd = gcd(array.get(k), gcd);
	 				if (!seen.contains(k) && tempgcd > maxgcd){
	 					maxgcd = tempgcd;
	 					maxindex = k;
	 				}
	 			}
	 			seen.add(maxindex);
	 			gcd = maxgcd;
	 			out.print(array.get(maxindex) + " ");
	 		}
	 		out.println();
 		}
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
	public static int gcd(int a, int b){ 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	   }
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	

