//I AM THE CREED
/* //I AM THE CREED
/* package codechef; // don't place package name! */
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;
import java.awt.Point;
public class Main{
    //#include <bits/stdc++. h> 
    public static void main(String[] args) throws IOException 
    { 
  
        Scanner input = new Scanner(System.in);
        input.nextInt();
        while(input.hasNext()){
            int n=input.nextInt();
            ArrayList<Integer> l=new ArrayList<>();
            int max=0;
            for(int i=0;i<n;i++){
                int ele=input.nextInt();
                l.add(ele);
                max=Math.max(max, ele);
            }
            ArrayList<Integer> sol=new ArrayList<>();
            sol.add(max);
            l.remove((Integer)(max));
            max=0;
            for(int j=1;j<n;j++){
                int ele=0;
                max=0;
                for(int i=0;i<l.size();i++){
                    sol.add(l.get(i));
                    int g=findGCD(sol);
                    if(g>max){
                        ele=l.get(i);
                        max=g;
                    }
                    sol.remove((Integer)(l.get(i)));
                }
                sol.add(ele);
                l.remove((Integer)(ele));
            }
            StringBuilder sb=new StringBuilder();
            for(int i=0;i<n;i++){
                sb.append(sol.get(i)+" ");
            }
            System.out.println(sb.toString());
        }
        
    }
    static int findGCD(ArrayList<Integer> arr) 
    { 
        int result = 0; 
        for (int i=0;i<arr.size();i++){ 
            result = gcd(result, arr.get(i)); 
  
            if(result == 1) 
            { 
               return 1; 
            } 
        } 
  
        return result; 
    } 
    static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 

}