import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner s = new Scanner (System.in);
      int t =s.nextInt();
      for (int i=0;i<t;i++)
      {
            
          int n =s.nextInt();
          int[] a = new int[n]; 
          for(int j=0;j<n;j++)
          {
              a[j] =s.nextInt();


          }
           Arrays.sort(a) ;
    n--;
         // System.out.print(a[n]);
          for (int x=n;x>=0;)
          {
              if ((a[n]%a[x])==0)
              System.out.print(" "+a[x]);
              x--;
          }
         for (int r=n;r>=0;)
         {
              if (a[n]%a[r]!=0)
             System.out.print(" "+a[r]);
             r--;
         }
          System.out.println(" ");
        }

    }}
