import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(in.readLine());
		int n, ind, div;
		for (int i = 0; i < t; i++) {
			n = Integer.parseInt(in.readLine());
			ArrayList<Integer> a = new ArrayList<Integer>();
			String[] tokens = in.readLine().split(" ");
			for (int j = 0; j < n; j++)
				a.add(Integer.parseInt(tokens[j]));
			Collections.sort(a);
			Collections.reverse(a);
			int[] b = new int[n];
			b[0] = a.get(0);
			a.remove(0);
			ind = 1;
			div = b[0];
			ArrayList<Integer> rem;
			loop:
			while (!a.isEmpty()) {
				for (int j = div; j > 0; j--) {
					if (div%j == 0) {
						rem = new ArrayList<Integer>();
						for (int k = 0; k < a.size(); k++) {
							if (a.get(k)%j == 0) {
								b[ind] = a.get(k);
								rem.add(k);
								ind++;
							}
						}
						if (!rem.isEmpty()) {
							Collections.reverse(rem);
							for (int k : rem) {
								a.remove(k);
							}
							div = j;
							continue loop;
						}
					}
				}

			}
			for (int j = 0; j < n; j++) {
				System.out.print(b[j]+" ");
			}
			System.out.println();
		}
	}
}
