import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int t;
        t = in.nextInt();
        while (t > 0) {
            solver.call(in,out);
            t--;
        }

        out.close();
    }

    static class TaskA {
        public void call(InputReader in, PrintWriter out) {
            int n , a=0 , b=0 , c=0 , d=0;
            n = in.nextInt();
            int[] arr = new int[n];
            LinkedList<Integer> linkedList = new LinkedList<>();
            for (int i = 0; i <n ; i++) {
                linkedList.add(in.nextInt());
                if(linkedList.get(i)>a)
                    a=linkedList.get(i);
            }
            linkedList.remove((Integer)a);
            arr[0]=a;

            for (int i = 1; i<n; i++) {
                for (int j = 0; j <linkedList.size() ; j++) {
                    b = gcd(linkedList.get(j) , a);

                    if(b>c) {
                        c = b;
                        d= linkedList.get(j);
                    }
                }
                arr[i] = d;
                linkedList.remove((Integer)d);
                a = c;
                c = 0;
                d =0;
            }
            for (int i = 0; i <n ; i++) {
                out.print(arr[i]+" ");
            }
           out.println();

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

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }

    }
}