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

public class B
{
    static int n;
    static int[] arr;
    static String str;
    public static void main(String[] args) throws IOException
    {
        Flash f = new Flash();
        
        int T = f.ni();
        for(int tc = 1; tc <= T; tc++){
            n = f.ni(); arr = f.arr(n);
            fn();
        }
    }
    
    static void fn()
    {
        int[] b = new int[n];
        int maxi = 0, ngcd = 0;
        for(int i = 0; i < n; i++){
            if(arr[i] > ngcd){
                ngcd = arr[i];
                maxi = i;
            }
        }
        
        b[0] = ngcd; arr[maxi] = 0;
        
        for(int i = 1; i < n; i++){
            int cgcd = 0, ci = 0;
            for(int j = 0; j < n; j++){
                if(arr[j] != 0 && gcd(ngcd, arr[j]) > cgcd){
                    cgcd = gcd(ngcd, arr[j]);
                    ci = j;
                }
            }
            
            b[i] = arr[ci];
            arr[ci] = 0;
        }
        
        StringBuilder sb = new StringBuilder();
        for(int x : b) sb.append(x + " ");
        System.out.println(sb);
    }
    
    static int gcd(int a, int b){
        if(a == 0) return b;
        if(b == 0) return a;
        
        if(a <= b) return gcd(a, b%a);
        else return gcd(b, a%b);
    }
    static void sort(int[] a){
        List<Integer> A = new ArrayList<>();
        for(int i : a) A.add(i);
        Collections.sort(A);
        for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
    }
    
    static int swap(int itself, int dummy)
    {
        return itself;
    }
    
    //SecondThread
    static class Flash
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        
        String next(){
            while(!st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            
            return st.nextToken();
        }
        
        String nextLine(){
            String s = new String();
            try{
                s = br.readLine().trim();
            }catch(IOException e){
                e.printStackTrace();
            }
            
            return s;
        }
        
        //nextInt()
        int ni(){
            return Integer.parseInt(next());
        }
        
        int[] arr(int n){
            int[] a = new int[n];
            for(int i = 0; i < n; i++) a[i] = ni();
            return a;
        }
        
        //nextLong()
        long nl(){
            return Long.parseLong(next());
        }
    }
}