import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class BigVova { // Template for CF
    public static class ListComparator implements Comparator<List<Integer>> {

        @Override
        public int compare(List<Integer> l1, List<Integer> l2) {
            for (int i = 0; i < l1.size(); ++i) {
                if (l1.get(i).compareTo(l2.get(i)) != 0) {
                    return l1.get(i).compareTo(l2.get(i));
                }
            }
            return 0;
        }
    }

    public static class Pair {
        int first;
        int second;

        public Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }

        public int getFirst() {
            return first;
        }

        public int getSecond() {
            return second;
        }

        @Override
        public String toString() {
            return first + " " + second;
        }
    }

    public static void main(String[] args) throws IOException {
        // Check for int overflow!!!!
        // Should you use a long to store the sum or smthn?
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int T = Integer.parseInt(f.readLine());
        for (int i = 0; i < T; i++) {
            int n = Integer.parseInt(f.readLine());
            StringTokenizer st = new StringTokenizer(f.readLine());
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < n; j++) {
                int a = Integer.parseInt(st.nextToken());
                list.add(a);
            }
            Collections.sort(list);
            List<Integer> order = new ArrayList<>();
            order.add(list.get(n - 1));
            boolean[] used = new boolean[n];
            int current = list.get(n - 1);
            for (int j = 0; j < n - 1; j++) {
                int max = 0;
                int ind = 0;
                for (int k = 0; k < n - 1; k++) {
                    if (!used[k]) {
                        int a = gcd(current, list.get(k));
                        if (max <= a) {
                            max = a;
                            ind = k;
                        }
                    }
                }
                order.add(list.get(ind));
                used[ind] = true;
                current = max;
            }
            for (int j = 0; j < n; j++) {
                out.print(order.get(j) + " ");
            }
            out.println();
        }
        out.close();
    }

    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
}