import java.util.function.Consumer;
import java.util.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.io.*;
import java.lang.Math.*;
 public class KickStart2020{
	static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){br = new BufferedReader(
           new InputStreamReader(System.in));}
        String next(){
            while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (IOException e) {e.printStackTrace();}}
            return st.nextToken();}
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next());}
        float nextFloat() {return Float.parseFloat(next());}
        String nextLine() {
            String str = "";
            try {str = br.readLine();}
            catch (IOException e) { e.printStackTrace();}
            return str; }}
	static String reverseOfString(String a) {
		StringBuilder ssd = new StringBuilder();
		for(int i = a.length() - 1; i >= 0; i--) {
			ssd.append(a.charAt(i));
		}
		return ssd.toString();
	}
	static char[] reverseOfChar(char a[]) {
		char b[] = new char[a.length];
		int j = 0;
		for(int i = a.length - 1; i >= 0; i--) {
			b[i] = a[j];
			j++;
		}
		return b;
	}
	static boolean isPalindrome(char a[]) {
		boolean hachu = true;
		for(int i = 0; i <= a.length / 2; i++) {
			if(a[i] != a[a.length - 1 - i]) {
				hachu = false;
				break;
			}
		}
		return hachu;
	} 
	static long gcd(long a, long b)
	{
	    if (b == 0)
	        return a;
	    return gcd(b, a % b);
	     
	}
	
		public static void main(String[] args) throws Exception{
FastReader sc = new FastReader();
        int t = sc.nextInt();
        while(t-- > 0) {
        	int n = sc.nextInt();
        	TreeSet<Integer> ss = new TreeSet<>();
        	for(int i = 0; i < n; i++) {
        		int a = sc.nextInt();
        		ss.add(a);
        	}
        	int arr[] = new int[n];
        	arr[0] = ss.last();
        	long gcd = arr[0];
        	ss.pollLast();
        	for(int i = 1; i < n; i++) {
        		long max = 0;
        		int ans = 0;
        		for(int e: ss) {
        			long z = gcd(gcd, e);
        			if(z > max) {
        				max = z;
        				ans = e;
        			}
        		}
        		arr[i] = ans;
        		gcd = max;
        		ss.remove(ans);
        	}
        	for(int e: arr) System.out.print(e  + " ");
        	System.out.println();
        }
		}
}
