import java.util.*;
import java.io.*;

public class _1407B {
    static int[] MODS = {1000000007, 998244353};
    static int MOD = MODS[0];

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
            }
            Arrays.sort(a);
            int max = a[n-1];
            Node[] c = new Node[n-1];
            ArrayList<Integer> list = new ArrayList<>();
            for (int i = 0; i < n-1; i++) {
                list.add(a[i]);
            }
            ArrayList<Integer> ans = new ArrayList<>();
            ans.add(max);
            if (n == 1) {
                continue;
            }
            int curgcd = max;
            for (int i = n-2; i >= 0; i--) {
                int index = 0;
                int gcd = gcd(curgcd, list.get(0));
                for (int j = 1; j <= i; j++) {
                    int temp = gcd(curgcd, list.get(j));
                    if (temp > gcd) {
                        index = j;
                        gcd = temp;
                    }
                }
                ans.add(list.get(index));
                curgcd = gcd;
                list.remove(index);
            }
            for (int i = 0; i < ans.size(); i++) {
                out.print(ans.get(i)+" ");
            }
            out.println();
        }
        out.close();
    }

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

    public static class Node implements Comparable<Node> {
        int value;
        int gcd;
        int max;
        public Node(int v, int m) {
            value = v;
            max = m;
            gcd = gcd(v, m);
        }

        public int compareTo(Node other) {
            return gcd-other.gcd;
        }
    }

    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
