import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        int t = readInt();
        while(t-->0) {
            int n = readInt();
            int[] a = readIntArray();
            Arrays.sort(a);
            Map<Integer, List<Integer>> m = new HashMap<>();
            for (int i = 0; i < n-1; i++) {
                m.putIfAbsent(a[i], new ArrayList<>());
                m.get(a[i]).add(i);
            }
            int[] b = new int[n];
            b[0] = a[n-1];
            int[] v = new int[n];
            v[n-1] = 1;
            int gcd = b[0];
            for(int i=1 ; i<n ; i++) {
                System.out.println(gcd);
                int ind = -1;
                int mxg = 0;
                for (int j = 0; j < n; j++) {
                    if(v[j]==0) {
                        int g = gcd(gcd, a[j]);
                        if(g>mxg) {
                            System.out.println(a[j] + " " + g);
                            mxg = g;
                            ind = j;
                        }
                        else if(g==mxg) {
                            if(m.get(a[j]).size() >= m.get(a[ind]).size()) {
                                ind = j;
                            }
                        }
                    }
                }
                v[ind]=1;
                b[i] = a[ind];
                gcd = mxg;
            }
            for (int i = 0; i < n; i++) {
                System.out.print(b[i]+" ");
            }
            System.out.println();
        }
    }

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


    private static String readString() throws Exception {
        return br.readLine();
    }

    private static int readInt() throws Exception{
        return Integer.parseInt(readString());
    }

    private static long readLong() throws Exception{
        return Long.parseLong(readString());
    }

    private static double readDouble() throws Exception{
        return Double.parseDouble(readString());
    }

    private static String[] readStringArray() throws Exception {
        return br.readLine().split(" ");
    }

    private static List<String> readStringList() throws Exception {
        return Arrays.asList(readStringArray());
    }

    private static List<Integer> readIntList() throws Exception {
        return readStringList().stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList());
    }

    private static int[] readIntArray() throws Exception {
        return readIntList().stream().mapToInt(i -> i).toArray();
    }

    private static List<Long> readLongList() throws Exception {
        return readStringList().stream().map(s -> Long.parseLong(s)).collect(Collectors.toList());
    }

    private static long[] readLongArray() throws Exception {
        return readLongList().stream().mapToLong(i -> i).toArray();
    }

    private static List<Double> readDoubleList() throws Exception {
        return readStringList().stream().map(s -> Double.parseDouble(s)).collect(Collectors.toList());
    }

    private static double[] readDoubleArray() throws Exception {
        return readDoubleList().stream().mapToDouble(i -> i).toArray();
    }
}