import java.util.*;

public class Big_Vova {

	static Scanner in = new Scanner(System.in);
	
	public static int gcd(int a, int b) {
		if(a==0) return b;
		return gcd(b%a, a);
	}
	
	public static void main(String[] args) {
		
		int t = in.nextInt();
		
		while(t-- > 0) {
			
			LinkedList<Integer> a = new LinkedList<>();
			int n = in.nextInt();
			
			for(int i = 0; i < n; i++) a.add(in.nextInt());
			
			Collections.sort(a);
			
			ArrayList<Integer> b = new ArrayList<>();
			
			b.add(a.get(n-1));
			a.remove(n-1);
			int gcd = b.get(0);
			
			while(!a.isEmpty()) {
				
				int ind = 0;
				int g = gcd(gcd,a.get(0));
				
				for(int i = 1; i < a.size(); i++) {
					
					int p = gcd(gcd,a.get(i));
					
					if(p > g) {
						ind = i;
						g = p;
					}
				}
				b.add(a.get(ind));
				a.remove(ind);
				gcd = g;
			}
			for(int k : b) System.out.print(k + " ");
			System.out.println();
		}
	}	
}