import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-->0) {
            int n = sc.nextInt();
            HashSet<Integer> set = new HashSet<>();
            HashMap<Integer, Integer> map = new HashMap<>();
            int currentGCD = 0;
            for(int i=0;i<n;i++){
                int a = sc.nextInt();
                set.add(a);
                int val = map.getOrDefault(a,0);
                currentGCD = Math.max(a,currentGCD);
                map.put(a,val+1);
            }
            ArrayList<Integer> ans = new ArrayList<>();
            ans.add(currentGCD); set.remove(currentGCD);
            while (!set.isEmpty()){
                int tmpMaxGCD = -1; int max = -1;
                for(int x: set){
                    int tmpGCD = get_gcd(currentGCD, x);
                    if(tmpGCD > tmpMaxGCD){
                        tmpMaxGCD = tmpGCD;
                        max = x;
                    }
                }
                int times = map.get(max);
                for(int i=0;i<times;i++){
                    ans.add(max);
                }
                currentGCD = tmpMaxGCD; set.remove(max);
            }
            for(int x : ans){
                System.out.print(x + " ");
            }
            System.out.println();
        }
    }

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