
/**
 *
 */

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

/**
 * @author b
 *
 */
public class B {

	public static void main(String[] args) {
		Scanner scanner = new Scanner();
		PrintWriter writer = new PrintWriter(System.out);
		int t = scanner.nextInt();
		for (int i = 0; i < t; i++) {
			solve(scanner, writer);
		}
		writer.close();
	}

	private static int gcd(int a, int b) {

		if (a == 0)
			return b;

		return gcd(b % a, a);

	}

	private static void solve(Scanner scanner, PrintWriter writer) {

		int n = scanner.nextInt();
		int[] as = scanner.nextIntArr(n);

		Arrays.sort(as);
		boolean[] taken = new boolean[n];
		int[] res = new int[n];
		res[0] = as[n - 1];
		taken[n - 1] = true;

		int currentGcd = res[0];
		for (int i = n - 2; i >= 0; i--) {

			int choosenIndex = -1;
			int bestGcd = -1;
			for (int j = 0; j < n; j++) {
				if (taken[j])
					continue;

				int gcdRes = gcd(currentGcd, as[j]);
				if (gcdRes > bestGcd) {
					bestGcd = gcdRes;
					choosenIndex = j;
				}
			}

			res[n - i - 1] = as[choosenIndex];
			taken[choosenIndex] = true;
			currentGcd = bestGcd;
		}

		for (int a : res) {
			writer.print(a + " ");
		}

		writer.println();
	}

	// Props to SecondThread
	static class Scanner {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tokenizer = new StringTokenizer("");

		String next() {
			while (!tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return tokenizer.nextToken();
		}

		long[] nextLongArr(int num) {
			long[] vals = new long[num];
			for (int i = 0; i < num; i++)
				vals[i] = nextLong();
			return vals;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArr(int numberOfElements) {
			int[] values = new int[numberOfElements];
			for (int i = 0; i < numberOfElements; i++)
				values[i] = nextInt();
			return values;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}
