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

public class BigVova {
    public static void main(final String[] args) {
        var fr = new FastReader();
        int t = fr.nextInt();
        while(t-- > 0) {
            int n = fr.nextInt();
            var a = new ArrayList<Integer>(n);
            while(n-- > 0) {
                a.add(fr.nextInt());
            }
            var x = solve(a);
            for(var z : x) System.out.printf("%d ", z);
            System.out.println();
        }
    }

    static ArrayList<Integer> solve(ArrayList<Integer> A) {
        int curr_max_gcd = A.stream().max((a, b) -> {
            return a < b ? -1 : 1;
        }).get();
        int curr_best_index = A.indexOf(curr_max_gcd);

        swap(A, 0, curr_best_index);
        int last_gcd = curr_max_gcd;
        for(int i = 1; i < A.size(); i++) {
            int local_best = 1;
            int index = i;
            for(int j = i; j < A.size(); j++) {
                int gcd = gcd(last_gcd, A.get(j));
                if(gcd > local_best) {
                    System.out.printf("%d %d %d\n", gcd, local_best, A.get(j));
                    local_best = gcd;
                    index = j;
                }
            }
            swap(A, i, index);
            last_gcd = local_best;
        }

        return A;
    }

    static void swap(ArrayList<Integer> A, int i, int j) {
        int tmp = A.get(i);
        A.set(i, A.get(j));
        A.set(j, tmp);
    }

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


    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 (final 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 (final IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}
