import java.util.*;

public class _1407B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            Integer[] arr = new Integer[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();


            Arrays.sort(arr, Collections.reverseOrder());
            int max = arr[0], num = arr[0];
            int j=0,curr=max,idx=0;
            int max2=-1,x=arr[0];
            System.out.print(max+ " ");
            for (int i = 1; i < n; i++) {
                max2 = -1;
                for (j = 1; j < n; j++) {
                    if (arr[j] != -1) {
                        x = gcd(curr, arr[j]);
                        if (x > max2) {
                            max2 = x;
                            idx = j;
                        }
                    }
                }
                curr = max2;
                System.out.print(arr[idx] + " ");
                arr[idx] = -1;
            }
            System.out.println();
        }
    }

    static int gcd(int a, int b) {
        return a == 0 ? b : gcd(b % a, a);
    }
}
