import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
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];
			for(int i=0;i<n;i++) {
				a[i]=sc.nextInt();
			}
			//int g=a[0];
//			for(int i=1;i<n;i++) {
//				g=gcd(g,a[i]);
//			}
			int idx1=-1,idx2=-1;
			int min=Integer.MAX_VALUE;
			boolean cont=true;
			for(int i=0;i<n-1;i++) {
			//	int g=a[i];
				for(int j=i+1;j<n;j++) {
					int g=gcd(a[i],a[j]);
					if(g<min) {
						min=g;
						idx1=i;
						idx2=j;
					}
				}
			}
			if(n==1) {
				out.println(a[0]);
			}else {
			out.print(a[idx1]+" "+a[idx2]);
			for(int i=0;i<n;i++) {
				if(i==idx1||i==idx2)continue;
				out.print(" "+a[i]);
			}
			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(); }


	}

}
