import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
public class Main {
public static void main(String[] args) {
    //solution start :-)
     		Scanner sc = new Scanner(System.in);
		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();
			}
			Arrays.sort(a);
			ArrayList<Integer> al = new ArrayList<>();
			ArrayList<Integer> al1 = new ArrayList<>();
			if(a[0]==1) {
				System.out.print(a[n-1]+" ");
				for(int i=0;i<(n-1);i++) {
					System.out.print(a[i]+" ");
				}
				System.out.println();
			}
			else {
			for(int i=0;i<n;i++) {
				if(a[i]%a[0]!=0) al.add(a[i]);
				else al1.add(a[i]);
			}
			Collections.sort(al,Collections.reverseOrder());
			for(Integer i:al) {
				System.out.print(i+" ");
			}
			for(Integer i:al1) {
				System.out.print(i+" ");
			}
			System.out.println();
			}
		}
    //solution end <-_->
}}