

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

public class CodeForces669BDumbSolution {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static final long[] POWERS_OF_TEN = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000,
            1000000000, 10000000000L, 100000000000L, 1000000000000L, 10000000000000L, 100000000000000L,
            1000000000000000L, 10000000000000000L, 100000000000000000L, 1000000000000000000L };
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    private static Long readLong() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }

    private static String readToken() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    public static void main(String[] args) throws IOException {
        int T = readInt();
        while (T-- > 0)
            solve();
        pw.close();
    }

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

    private static void solve() throws IOException {
        ArrayList<Integer> dumbAnswer = new ArrayList<>();
        ArrayList<Integer> dumbFinalAnswer = new ArrayList<>();
        int len = readInt();
        //int len2 = len;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < len; i++) {
            int tempNum = readInt();
            dumbAnswer.add(tempNum);
            if (tempNum > max) {
                max = tempNum;
            }
        }
        Collections.sort(dumbAnswer);
        int current = max;
        dumbAnswer.remove(dumbAnswer.size() - 1);
        dumbAnswer.add(current);
        for (int i = 0; i < len; i++) { //nested for loop time
            int max2 = Integer.MIN_VALUE;
            int max3 = 0;
            int max3index = 0;
            for (int j = 0; j < dumbAnswer.size(); j++) {
                int next = dumbAnswer.get(j);
                int temp2 = gcd(current, next);
                if (temp2 > max2) {
                    max2 = temp2;
                    max3 = next;
                    max3index = j;
                }
            }
            dumbFinalAnswer.add(max3);
            current = max2;
            //dumbAnswer.remove(dumbAnswer.get(max2)); //fix this // fixed :) //
            dumbAnswer.remove(max3index);
        }
        for (int i = 0; i < dumbFinalAnswer.size(); i++) {
            pw.print(dumbFinalAnswer.get(i) + " ");
        }
        pw.println();
    }
}
