import java.util.*;
import java.io.*;

public class main{

	static Scanner in = new Scanner(System.in);
	static int num[] = {2,3,5,7,11,13,17,19,23,29,31};

	static int gcd(int a,int b){
		if (b==0) return a;
		else return gcd(b,a%b);
	}

	static void solve(){

		int n = in.nextInt(), all[] = new int[n], mx=0, ans[] = new int[n];
		boolean used[] = new boolean[n];

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

		for (int i=0;i<n;i++) if (mx==all[i]){used[i] = true;break;}

		ans[0] = mx;
		for(int i=1;i<n;i++){
			int us = 0,best = 0;

			for(int j=0;j<n;j++){
				if (used[j]==false)
					if (best<gcd(mx,all[j])){
						best = gcd(mx,all[j]);
						us = all[j];
					}
			}

			for (int j=0;j<n;j++)
				if (all[j]==us){
					used[j] = true;
					break;
				}

			mx = best;
			ans[i] = us;
		}

		for (Integer x:ans) System.out.print(x+" ");
		System.out.print('\n');

	}

	public static void main(String args[]){
		int t = in.nextInt();
		while (t>0){
			t--;
			solve();
		}
	}

}