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, max, 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];
			max = 0;
			ind = 0;
			for (int j = 0; j < n; j++) {
				if (a.get(j) > max) {
					max = a.get(j);
					ind = j;
				}
			}
			b[0] = max;
			a.remove(ind);
			ind = 1;
			ArrayList<Integer> rem;
			for (int j = 1; j <= b[0]; j++) {
				if (b[0]%j == 0) {
					div = b[0]/j;
					rem = new ArrayList<Integer>();
					for (int k = 0; k < a.size(); k++) {
						if (a.get(k)%div == 0) {
							b[ind] = a.get(k);
							rem.add(k);
							ind++;
						}
					}
					Collections.reverse(rem);
					for (int k : rem) {
						a.remove(k);
					}
 				}
			}
			for (int j = 0; j < n; j++) {
				System.out.print(b[j]+" ");
			}
			System.out.println();
		}
	}
}
