import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Try {
	public static int computeGcd(int num1,int num2 ) {
		if(num2==0) {
			return num1;
		}
		return computeGcd(num2, num1%num2);
	}
	
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		int t = sc.nextInt();
		
		for (int testcase = 1; testcase <= t; ++testcase) {
			int n = sc.nextInt();
			ArrayList<Integer> list = new ArrayList<Integer>();
			int maxNum = Integer.MIN_VALUE;
			int maxInd=0;
			for( int ind=0 ; ind<n ; ++ind ) {
				int num = sc.nextInt();
				list.add(num);
				if( num>maxNum ) {
					maxNum = num;
					maxInd = ind;
				}
			}
			out.print(maxNum+" ");
			list.remove(maxInd);
			int curGcd = maxNum;
			for( int itr=1 ; itr<=(n-1) ; ++itr ) {
				maxNum = Integer.MIN_VALUE;
				maxInd=0;
				for( int ind=0 ; ind<list.size() ; ++ind ){
					int num1 = curGcd>list.get(ind)?curGcd:list.get(ind); 
					int num2 = curGcd+list.get(ind)-num1;
					int tempGcd = computeGcd(num1, num2);
					if( tempGcd>maxNum ) {
						maxNum = tempGcd;
						maxInd = ind;
					}
				}
				out.print(list.get(maxInd)+" ");
				list.remove(maxInd);
			}
			out.println();
		}

		out.close();
	}

	// -----------PrintWriter for faster output---------------------------------
	public static PrintWriter out;

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			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());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	// --------------------------------------------------------
}