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

public class BigVola {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int tests = sc.nextInt();
		
		for(int t=0; t<tests; t++) {
			int n = sc.nextInt();
			int[] arr = new int[n];
			int maximum = 0;
			ArrayList<Integer> remaining = new ArrayList<>();
			for(int i=0; i<n; i++) {
				arr[i]=sc.nextInt();
				maximum = Math.max(arr[i],maximum);
			}
			Arrays.sort(arr);
			
			for(int i=arr.length-2; i>=0; i--) {
				remaining.add(arr[i]);
			}
			int[] ans  = new int[arr.length];
			ans[0]=maximum;
			ArrayList<Integer> factors = new ArrayList<>();
			
			for(int i = 1; i<=maximum; i++) {
				if(maximum%i==0) {
					factors.add(i);
				}
			}
			int index = 1;
			for(int i=factors.size()-1; i>=0; i--) {
				for(int j=0; j<remaining.size(); j++) {
					if(remaining.get(j)%factors.get(i)==0) {
						ans[index++]=remaining.get(j);
						remaining.remove(j);
						i++;
						break;
					}
				}
				if(remaining.size()==0) {
					break;
				}
			}
			for(int i=0; i<ans.length-1; i++) {
				System.out.print(ans[i]+" ");
			}
			System.out.println(ans[ans.length-1]);
		}

	}

}
