import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int tc = sc.nextInt();
		while (tc-- > 0) {
			int n = sc.nextInt();
			int a[] = new int[n];
			boolean t[] = new boolean[n];
			int max = -1;
			int id = 0;
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				if(max < a[i]) {
					max = a[i];
					id = i;
				}
			}
			
			int res[] = new int[n];
			res[0] = max;
			
			int prevGCD = max;
			t[id] = true;
			
			for(int i = 1;i < n;i++) {
				int local_max = -1;
				int local_id = -1;
				for(int j = 0;j < n;j++) {
					if(t[j])
						continue;
					if(local_max < gcd(prevGCD,a[j])) {
						local_max = gcd(prevGCD,a[j]);
						local_id = j;
					}
				}
				res[i] = a[local_id];
				t[local_id] = true;
				prevGCD = gcd(a[local_id], prevGCD);
			}
			
			for (int i = 0; i < res.length; i++) {
				if(i > 0)
					System.out.print(" ");
				System.out.print(res[i]);
			}
			System.out.println();
			
		}

	}

	private static int gcd(int a, int b) {
		if (b > a) {
			int temp = a;
			a = b;
			b = temp;
		}
		return b == 0 ? a : gcd(b, a % b);
	}
}