import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class N1407B {

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt();
			int[]a=new int[n];
			boolean v[]=new boolean[n];
			int max=Integer.MIN_VALUE,idx=-1;
			for(int i=0;i<n;i++) {
				a[i]=sc.nextInt();
				if(a[i]>max) {
					max=a[i];
					idx=i;
				}
			}
			v[idx]=true;
			out.print(max+" ");
			if(n>1) {
				int x=1;
				int g=max;
				while(x<n) {
				    max=Integer.MIN_VALUE;
				    idx=-1;
					for(int i=0;i<n;i++) {
						int h=gcd(g,a[i]);
						if(!v[i]&&h>max) {
							max=h;
							idx=i;
						}
					}
					v[idx]=true;
					g=gcd(g,a[idx]);
					out.print(a[idx]+" ");
					x++;
				}
			}
			out.println();
		
		}
		
		out.close();

	}
	static int gcd (int a, int b) {
	    return b==0?a:gcd (b, a % b);
	}
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public boolean hasNext() {return st.hasMoreTokens();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
			
		public boolean ready() throws IOException {return br.ready(); }


	}

}
