import java.util.ArrayList;
import java.util.Scanner;

public class CF669B {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int c = 0 ; c < t ; c++){
            int n = in.nextInt();
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0 ; i < n; i++){
                a.add(in.nextInt());
            }
            int x = 0, g = Integer.MIN_VALUE;
            int[] rV = new int[n];
            for (int i = 0 ; i < n; i++){
                if(a.get(i) > g){
                    x = i;
                    g = a.get(i);
                }
            }
            rV[0] = a.get(x);
            a.remove(x);
            int m;
            int h = 1;
            while(a.size() != 0){
                m = Integer.MIN_VALUE;
                x = -1;
                for (int i = 0 ; i < a.size(); i++){
                    int l = gcd(a.get(i), g);
                    if (l > m){
                        x = i;
                        m = l;
                    }
                }
                rV[h] = a.get(x);
                a.remove(x);
                g = m;
                h++;
            }
            for (int i = 0 ; i < n; i++){
                System.out.print(rV[i] + " ");
            }
            System.out.println();
        }
    }

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