//   package com.company.codeforces;










import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;



public class Solution {


    public static void main(String[] args) {
        FastReader input = new FastReader();
        int t = input.nextInt();

        while (t-- > 0) {


            int n = input.nextInt();
            ArrayList<Integer>a = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                int temp = input.nextInt();
                a.add(temp);
            }
           Collections.sort(a,Collections.reverseOrder());

            StringBuilder sbone=new StringBuilder();
            System.out.print(a.get(0)+" ");
            int min=a.get(0);
            int maxgcd=1;
            int aa=0;
            boolean ans[]=new boolean[n];
            ans[0]=true;

            for (int j = 0; j <n-1 ; j++) {
               maxgcd=1;
                for (int i = 1; i < n; i++) {
                    if (!ans[i]) {
                        int k = gcd(min, a.get(i));


                        if (k > maxgcd) {
                            maxgcd = k;
                            aa = i;

                        }

                    }
                }
                if (maxgcd==1){
                    break;
                }
                ans[aa]=true;
                min=maxgcd;

               sbone.append(a.get(aa)+" ");
            }
            System.out.print(sbone);
            for (int i = 0; i <n ; i++) {
                if (!ans[i]) System.out.print(a.get(i)+" ");
            }
            System.out.println();

        }
    }
    static boolean isprime[]=new boolean[1001];
    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

//    static void sieveOfEratosthenes(int n)
//    {
//        // Create a boolean array "prime[0..n]" and initialize
//        // all entries it as true. A value in prime[i] will
//        // finally be false if i is Not a prime, else true.
//        boolean prime[] = new boolean[n+1];
//        for(int i=0;i<n;i++)
//            prime[i] = true;
//
//        for(int p = 2; p*p <=n; p++)
//        {
//            // If prime[p] is not changed, then it is a prime
//            if(prime[p] == true)
//            {
//                // Update all multiples of p
//                for(int i = p*p; i <= n; i += p)
//                    prime[i] = false;
//            }
//        }
//
//        // Print all prime numbers
//        for(int i = 2; i <= n; i++)
//        {
//            if(prime[i] == true)
//               isprime[i]=true;
//        }
//    }







    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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




}