
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;

public class B {

	public static void main(String[] srgs) {

		Scanner nik = new Scanner(System.in);
		int t = nik.nextInt();
		StringBuilder st = new StringBuilder();
		while (t-- > 0) {
			int n = nik.nextInt();
			int[] a = new int[n];
			int max = Integer.MIN_VALUE;

			for (int i = 0; i < n; i++) {
				a[i] = nik.nextInt();
				max = Math.max(max, a[i]);
			}

			boolean[] b = new boolean[n];
			ArrayList<Integer> a1 = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				if (max % a[i] == 0) {
					b[i] = true;
					a1.add(a[i]);
				}
			}
			Collections.sort(a1, Collections.reverseOrder());

			for (int i = 0; i < a1.size(); i++) {
				st.append(a1.get(i) + " ");
			}

			for (int i = 0; i < n; i++) {
				if (b[i] == false) {
					st.append(a[i] + " ");
				}
			}
			st.append("\n");

		}
		System.out.println(st);
	}

}