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

public class Main {
    static FastScanner in = new FastScanner();

    static int gcd(int a, int b) {
        int r;
        while (b != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    static void solve() {
        int n = in.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; ++i)
            a.add(in.nextInt());
        Collections.sort(a, Collections.reverseOrder());
        Collections.sort(a, (b, c) -> (gcd(a.get(0), c) - gcd(a.get(0), b)));

        ArrayList<Integer> b = new ArrayList<>();
        System.out.print(a.get(0) + " ");
        for (int i = 1; i < n; ++i) {
            if (a.get(0) % a.get(i) == 0)
                System.out.print(a.get(i) + " ");
            else
                b.add(a.get(i));
        }
        for (int el : b)
            System.out.print(el + " ");
        System.out.println();
    }

    public static void main(String[] args) {
        int T = in.nextInt();
        while (T-- > 0)
            solve();
    }

    static class Pair<X, Y> {
        X x;
        Y y;

        public Pair(X x, Y y) {
            this.x = x;
            this.y = y;
        }
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner() {
        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;
    }
}