/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class B
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         while(T-->0)
         {
            int N = Integer.parseInt(infile.readLine());
            int[] arr = new int[N];
            st = new StringTokenizer(infile.readLine());
            for(int i=0; i < N; i++)
               arr[i] = Integer.parseInt(st.nextToken());
            sort(arr);
            int[] res = new int[N];
            res[0] = arr[N-1];
            HashSet<Integer> seen = new HashSet<Integer>();
            int gcd = arr[N-1];
            seen.add(N-1);
            for(int i=1; i < N; i++)
            {
               int temp = gcd;
               int dex = -1;
               for(int a=0; a < N; a++)
               {
                  if(seen.contains(a))
                     continue;
                  if(dex == -1 || temp < gcd(gcd, arr[a]))
                  {
                     temp = (int)gcd(gcd, arr[a]);
                     dex = a;
                  }
               }
               res[i] = arr[dex];
               gcd = temp;
               seen.add(dex);
            }
            for(int x: res)
               sb.append(x+" ");
            sb.append("\n");
         }
         System.out.print(sb);
      }
      public static long gcd(long a, long b)
      {
         if(a > b)
         {
            long t = a;
            a = b;
            b = t;
         }
         if(a == 0L)
            return b;
         return gcd(b%a, a);
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }