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

public class Main {
    static int M = 1_000_000_007;

    private static int[] testCase(int n, int[] a) {
        int[] b = new int[n];
        int ci, idx = 1;

        ArrayList<Integer> nums = new ArrayList<>();

        for (int ai : a) nums.add(ai);

        Collections.sort(nums);

        b[0] = nums.get(nums.size() - 1);
        ci = b[0];

        nums.remove(nums.size() - 1);

        while (!nums.isEmpty()) {
            int maxGcd = 0, maxIndex = -1;

            for (int i = 0; i < nums.size(); i++) {
                int currGcd = gcd(ci, nums.get(i));

                if (currGcd > maxGcd) {
                    maxGcd = currGcd;
                    maxIndex = i;
                } else if (currGcd == maxGcd) {
                    if (nums.get(i) > nums.get(maxIndex)) {
                        maxIndex = i;
                    }
                }
            }

            ci = maxGcd;
            b[idx++] = nums.get(maxIndex);
            nums.remove(maxIndex);
        }


        return b;
    }

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

    public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();  // Scanner has functions to read ints, longs, strings, chars, etc.
        //in.nextLine();
        for (int tt = 1; tt <= t; ++tt) {
            int n = in.nextInt();
            int[] a = in.readArray(n);

            int[] b = testCase(n, a);

            for (int bi : b) {
                out.print(bi + " ");
            }

            out.println();
        }

        out.close();
    }

    private static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        char[] readCharArray(int n) {
            char[] arr = new char[n];
            try {
                br.read(arr);
                br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return arr;
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

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