import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;


/*
1
10
589 183 43 474 82 960 388 804 930 118

960 930 474 804 183 589 43 82 388 118
 */


public class B {
    public static void main(String[] args) {
        FastInput input = new FastInput();
        PrintWriter output = new PrintWriter(System.out);
        int t = input.nextInt();
        while (t-- > 0) {
            int n = input.nextInt();
            ArrayList<Integer> arr = new ArrayList<>();
            ArrayList<Integer> ans = new ArrayList<>();
            for (int i = 0; i < n; i++) arr.add(input.nextInt());
            Collections.sort(arr, Collections.reverseOrder());


            int reference = arr.remove(0);
            ans.add(reference);
            
            while (ans.size() < n) {
                int maxGCD = 1;
                int indexOfMaxGCD = 0;
                for (int i = 0; i < arr.size(); i++) {
                    if (GCD(ListGCD(ans), arr.get(i)) > maxGCD) {
                        maxGCD = GCD(ListGCD(ans), arr.get(i));
                        indexOfMaxGCD = i;
                    }
                }
                ans.add(arr.remove(indexOfMaxGCD));
            }

            for (int e : ans) output.print(e + " ");
            output.println();
        }
        output.close();
    }

    static int GCD(int n1, int n2) {
        int ans = 1;
        for (int i = 1; i <= n1 && i <= n2; i++) {
            if (n1 % i == 0 && n2 % i == 0) ans = i;
        }
        return ans;
    }

    static int ListGCD(ArrayList<Integer> list) {
        int result = 0;
        for (int e : list) {
            result = GCD(result, e);
            if (result == 1) return 1;
        }
        return result;
    }

    static class FastInput {
        BufferedReader br;
        StringTokenizer st;

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

