
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class BigVova {

    static int gcd(int a, int b) {

        while (b != 0) {
            int t = a;
            a = b;
            b = t % b;
        }
        return a;

    }

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int q = scan.nextInt();
        while (q-- > 0) {
            int n = scan.nextInt();
            int[] a = new int[n];
            ArrayList<Integer> arr = new ArrayList<Integer>();
            for (int i = 0; i < n; i++) {
                arr.add(scan.nextInt());
            }
            Collections.sort(arr, Collections.reverseOrder());
            int t = 0;
            int g = 0;
            a[0] = arr.get(0);
            arr.remove(0);

            for (int i = 0; i < arr.size(); i++) {
                g = gcd(a[t], arr.get(i));
                int p = i;
                for (int j = 0; j < arr.size(); j++) {
                    if (gcd(a[t], arr.get(j)) >= g) {
                        g = gcd(a[t], arr.get(j));
                        p = j;
                    }
                }
                a[++t] = arr.get(p);
                arr.remove(p);
                --i;
            }
            for (int i = 0; i < n; i++) {
                System.out.print(a[i] + " ");
            }
            System.out.println();

        }

    }

}
