import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ks = sc.nextInt();
        int mod = 1000000007;

        for (int i = 0; i < ks; i++) {
            int n = sc.nextInt();
            Integer arr[] = new Integer[n];
             for (int j = 0; j < n; j++) {
                arr[j] = sc.nextInt();
             }

             if (n == 1) {
                System.out.println(arr[0]);
                continue;
             }

             Arrays.sort(arr, Collections.reverseOrder());
             int prevGcd = 1;
             for (int j = 1; j < n; j++) {
                if (gcdBySteinsAlgorithm(arr[0], arr[j]) > prevGcd ) {
                    prevGcd = gcdBySteinsAlgorithm(arr[0], arr[j]);
                }
            }


             for (int j = 1; j < n; j++) {
                int temp = 1;
                int idx = 1;
                for (int k = j + 1; k < n; k++) {
                    int findgcd = gcdBySteinsAlgorithm(prevGcd, arr[k]);
                    if (findgcd > temp) {
                        idx = k;
                        temp = findgcd;
                    }
                    int tempswap = arr[j];
                    arr[j] = arr[idx];
                    arr[idx] = tempswap;
                    prevGcd = temp;
                }
             }
             System.out.print(arr[0]);
             for (int j = 1; j < n; j++) {
                System.out.print(" " + arr[j]);
             }
             System.out.println("");
        }
    }

    public static int gcdBySteinsAlgorithm(int n1, int n2) {
        if (n1 == 0) {
            return n2;
        }
     
        if (n2 == 0) {
            return n1;
        }
     
        int n;
        for (n = 0; ((n1 | n2) & 1) == 0; n++) {
            n1 >>= 1;
            n2 >>= 1;
        }
     
        while ((n1 & 1) == 0) {
            n1 >>= 1;
        }
     
        do {
            while ((n2 & 1) == 0) {
                n2 >>= 1;
            }
     
            if (n1 > n2) {
                int temp = n1;
                n1 = n2;
                n2 = temp;
            }
            n2 = (n2 - n1);
        } while (n2 != 0);
        return n1 << n;
    }
}