import java.util.*;
import java.lang.*;
import java.io.*;
  

public  class sortmapKey { 
   
   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 s=new FastReader(); 
         int n=s.nextInt();
	for(int g=0;g<n;g++){
	   int size=s.nextInt();
	   int a[]=new int[size];
	   int num=0,l=0,k=0,m=0;
	   for(int u=0;u<size;u++){
	       a[u]=s.nextInt();
	       if(a[u]>num){
	           num=a[u];
	       }
	   }
	    System.out.print(num+" ");
      for(int u=0;u<size;u++){
          int i;
           for( i=0;i<size;i++){
              if(a[i]!=num&&a[i]!=-1&&gcd(a[i],num)>k){
                  k=gcd(a[i],num);
                  l=a[i];
                  m=i;
              } 
           }
           a[m]=-1;
           k=0;
           if(u==size-1)break;
           System.out.print(l+" ");
      }
       System.out.println();
    }
       }
     public static int gcd(int a,int b) {
         if(b==0)return a;
         else{
             return gcd(b,a%b);
         }
     }
  }