import java.util.*;
import java.io.*;
public class A {
	public static void primeFactors(int n, ArrayList<Integer> fact) 
    { 
		for (int i=1; i<=Math.sqrt(n); i++) 
        { 
            if (n%i==0) 
            { 
                if (n/i == i) 
                	fact.add(i);
                else { 
                	fact.add(i);
                	fact.add(n/i);
                } 
            } 
        } 
		Collections.sort(fact, Collections.reverseOrder());
    } 
	public static void main(String args[]) {
		FastScanner in = new FastScanner();
		int t=in.nextInt();
		while(--t>=0) {
			int n=in.nextInt();
			int tmp[]=in.nextArray(n);
			Arrays.sort(tmp);
			int a[]=new int[n];
			for(int i=0;i<n;i++)
				a[i]=tmp[n-i-1];
			
			
			
			ArrayList<Integer> arr=new ArrayList<>();
			arr.add(a[0]);
			ArrayList<Integer> fact=new ArrayList<>();
			primeFactors(a[0], fact);
			a[0]=-1;
			
//			System.out.println(fact);
			
			for(int facts: fact) {
				for(int i=0;i<n;i++) {
					if(a[i]%facts==0 && a[i]!=-1){
						arr.add(a[i]);
						a[i]=-1;
					}
				}
			}
			
			for(int i=0;i<n;i++)
				System.out.print(arr.get(i)+" ");
			System.out.println();
		}
	}

	///////////////////////////
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

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

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

		int[] nextArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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