import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer;
import java.util.*;
public class codeforcesB{
   static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
 
        public FastReader() 
        { 
            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; 
        } 
    } 
   public static void main(String args[]){
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        while(t-->0){
            StringBuilder sb=new StringBuilder();
          int n=sc.nextInt();
          int ar[]=new int[n];
          for(int i=0;i<n;i++){ar[i]=sc.nextInt();}
          Arrays.sort(ar);
          int br[]=new int[n];
          int max=ar[n-1];
          for(int i=0;i<n;i++){
            br[i]=gcd(ar[i],max);
            }
          for(int i=0;i<n;i++){
              int ans=0,pos=0;
               for(int j=0;j<n;j++){
                   if(br[j]>ans){ans=br[j];pos=j;}
                }
                br[pos]=-1;
                sb.append(ar[pos]+" ");
            }  
            System.out.println(sb.toString());
        }
   } 
    static int gcd(int a, int b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
}