import java.util.*;

public class _1407B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            Integer[] arr = new Integer[n];
            Integer[] brr = new Integer[n];
            int max=-1;
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();

            Arrays.sort(arr,Collections.reverseOrder());
            max=arr[0];
            arr[0]=-1;
            Vector<Integer> v= new Vector<>();
            for(int i=1,k=0;i<n;i++) {
                if (max % arr[i] == 0) {
                    v.add(arr[i]);
                    arr[i] = -1;
                }
            }
            System.out.print(max+ " ");
            Collections.sort(v,Collections.reverseOrder());
            for(int i=0;i<v.size();i++)
                System.out.print(v.get(i) + " ");
            for(int i=0;i<n;i++){
                if(arr[i]!=-1)
                    System.out.print(arr[i]+ " ");
            }
            System.out.println();
        }
    }
}
