import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class DynamicProgramming {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int t = scn.nextInt();
		for (int i = 0; i < t; i++) {
			int n = scn.nextInt();
			int[] arr = new int[n];
			for (int j = 0; j < n; j++) {
				arr[j] = scn.nextInt();
			}
			fun(arr);
			System.out.println();
		}
	}

	public static void fun(int[] arr) {

		int max = Integer.MIN_VALUE;
		for (int ele : arr)
			max = Math.max(max, ele);
		final int m = max;
		PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> {
			return gcd(m, b) - gcd(m, a);
		});
		pq.add(max);
		for (int ele : arr) {
			if (ele == max)
				continue;
			pq.add(ele);
		}

		while (!pq.isEmpty()) {
			System.out.print(pq.remove() + " ");
		}
	}

	public static int gcd(int n1, int n2) {
		int g = 1;
		for (int i = 1; i <= n1 && i <= n2; ++i) {
			if (n1 % i == 0 && n2 % i == 0)
				g = i;
		}
		return g;
	}

}
