import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        var sc = new Scanner(System.in);
    
        int T = Integer.parseInt(sc.next());
        var pw = new PrintWriter(System.out);
        for(int t = 0; t < T; t++){
            int n = Integer.parseInt(sc.next());
            var a = new int[n];
            int max = 0;
            int maxID = 0;
            for(int i = 0; i < n; i++){
                a[i] = Integer.parseInt(sc.next());
                if(a[i] > max){
                    max = a[i];
                    maxID = i;
                }
            }
            var used = new boolean[n];
            pw.print(a[maxID] + " ");
            used[maxID] = true;
            int gcd = a[maxID];
            for(int i = 0; i < n-1; i++){
                max = 0;
                for(int j = 0; j < n; j++){
                    if(used[j]) continue;
                    int x = gcd(a[j], gcd);
                    if(x > max){
                        max = x;
                        maxID = j;
                    }
                }
                pw.print(a[maxID] + " ");
                used[maxID] = true;
                gcd = gcd(a[maxID], gcd);
            }
            pw.println();
        }
        pw.flush();
    }
    
    static int gcd(int a, int b){
        return b == 0 ? a : gcd(b, a%b);
    }
}