import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader file = new BufferedReader(new InputStreamReader(System.in));
		int inputs = Integer.parseInt(file.readLine());
		while(inputs-->0) {
			int n = Integer.parseInt(file.readLine());
			StringTokenizer st = new StringTokenizer(file.readLine());
			int[] nums = new int[n];
			for(int i = 0; i < n; i++) {
				nums[i] = Integer.parseInt(st.nextToken());
			}
			Arrays.sort(nums);
			StringBuilder ans = new StringBuilder();
			ans.append(nums[n-1]);
			boolean[] used = new boolean[n];
			used[n-1] = true;
			int[] gcd = new int[n];
			Arrays.fill(gcd, Integer.MAX_VALUE);
			int prev = nums[n-1];
			for(int i = 1; i < n; i++) {
				int max = 0, id = -1;
				for(int j = 0; j < n; j++) {
					if(used[j])
						continue;
					gcd[j] = Math.min(gcd[j], GCD(nums[j], prev));
					if(gcd[j] > max) {
						max = gcd[j];
						id = j;
					}
				}
				ans.append(" " + nums[id]);
				prev = nums[id];
				used[id] = true;
			}
			System.out.println(ans);
		}

	}

	public static int GCD(int a, int b) {
		if(b == 0)
			return a;
		return GCD(b, a%b);
	}
	
}
