import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
    public static void main(String[] args) {
        FastReader in = new FastReader();
        int t = in.nextInt();
        StringBuilder sb = new StringBuilder();
        while(t-- > 0){
            int n = in.nextInt();
            int arr[] = new int[n];
            for(int i = 0; i < n; i++){
                arr[i] = in.nextInt();
            }
            Arrays.sort(arr);
            int gcd = arr[n-1];
            for(int i = n - 2; i >= 0; i--){
                 int max = Integer.MIN_VALUE;
                 int ind = i;
                  for(int j = i ; j >= 0; j--){
                      int val = gcd(gcd,arr[j]);
                      if(max < val){
                          max = val;
                          ind = j;
                      }
                  }
               // System.out.println(arr[i]+"---->>>"+arr[ind]+"--->GCD"+gcd+"i---->"+i+"ind ---> "+ind);
                  gcd = max;
                  int temp = arr[i];
                  arr[i] = arr[ind];
                  arr[ind] = temp;

            }

            for(int i = n - 1; i >= 0; i--){
                sb.append(arr[i]+" ");
            }
            sb.append("\n");
        }
        System.out.println(sb);
    }
    public static int gcd(int a, int b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }
}
