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

public class BigVova {

    public static int gcd(int a, int b) {
        if(b == 0) return a;
        return gcd(b, Math.abs(a - b));
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        while(t-- > 0) {
            int n = s.nextInt();
            ArrayList<Integer> a = new ArrayList<>();
            ArrayList<Integer> b = new ArrayList<>();
            int max_index = 0;
            for(int i = 0; i < n; i++) a.add(s.nextInt());
            for(int i = 0; i < n; i++) {
                if(a.get(i) > a.get(max_index)) max_index = i;
            }
            int max = a.get(max_index);
            b.add(a.remove(max_index));
            while(a.contains(max)) b.add(a.remove(max));
            while(!a.isEmpty()) {
                int max_gcd = 1, index = 0;
                for (int i = 0; i < a.size() - 1; i++) {
                    for (int j = i + 1; j < a.size(); j++) {
                        int gcd = gcd(a.get(i), a.get(j));
                        if (gcd > max_gcd) {
                            max_gcd = gcd;
                            index = i;
                        }
                    }
                }
                b.add(a.remove(index));
                for(int i = 0; i < a.size(); i++)
                    if(a.get(i) % max_gcd == 0) b.add(a.remove(i));
            }
            for(int i : b) System.out.print(i + " ");
        }
    }
}
