import java.util.ArrayList;
import java.util.Scanner;

public class BigVova {

    public static int gcd(int a, int b) {
        if(b == 0) return a;
        return gcd(b, Math.abs(a - b));
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        while(t-- > 0) {
            int n = s.nextInt();
            int[] a = new int[n];
            ArrayList<Integer> b = new ArrayList<>();
            int max_index = 0;
            for(int i = 0; i < n; i++) {
                a[i] = s.nextInt();
                max_index = a[max_index] > a[i] ? max_index : i;
            }
            b.add(a[max_index]);
            a[max_index] = 0;
            int last = b.get(0);
            for(int i = 0; i < n; i++) {
                int max_gcd = 0, index = 0;
                for(int j = 0; j < n; j++) {
                    if(gcd(last, a[j]) > max_gcd && a[j] != 0) {
                        max_gcd = gcd(last, a[j]);
                        index = j;
                    }
                }
                b.add(a[index]);
                last = a[index];
                a[index] = 0;
            }
            b.remove(b.size() - 1);
            for(int i : b) System.out.print(i + " ");
            System.out.println();
        }
    }
}
