import java.io.*;
import java.util.*;
public class Main {
	static int gcd(int a,int b) {
		if(a==0) return b;
		else return gcd(b%a,a);
	} 
	public static void main(String[] args) throws IOException 
	{ 
		FastScanner f = new FastScanner(); 
		int ttt=1;
		ttt=f.nextInt();
		PrintWriter out=new PrintWriter(System.out);
		for(int tt=0;tt<ttt;tt++) {
			int n=f.nextInt();
			int[] l=f.readArray(n);
			Arrays.sort(l);
			boolean[] v=new boolean[n];
			ArrayList<Integer> ans=new ArrayList<>();
			ans.add(l[n-1]);
			v[n-1]=true;
			int gcd=l[n-1];
			for(int k=0;k<n-1;k++) {
				int ind=-1;
				int mx=-1;
				for(int i=0;i<n;i++) {
					if(!v[i]) {
						int curr=gcd(gcd,l[i]);
						if(curr>mx) {
							mx=curr;
							ind=i;
						}
					}
				}
				gcd=mx;
				ans.add(l[ind]);
				v[ind]=true;
			}
			
			for(int i:ans) System.out.print(i+" ");
			System.out.println();
		}
		out.close();
	} 
	static void sort(int[] p) {
        ArrayList<Integer> q = new ArrayList<>();
        for (int i: p) q.add( i);
        Collections.sort(q);
        for (int i = 0; i < p.length; i++) p[i] = q.get(i);
    }
    
	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[] readArray(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());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
	}
} 	