// package CodeForcesContests;

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

public class zCF_669_2_B {

	public static void main(String args[]) 
	{
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		
		outer:
		for(int x = 1; x<= t; x++)
		{
			int n = sc.nextInt();
			int arr[] = new int[n];
			for(int i = 0;i<= n-1; i++)
			{
				arr[i] = sc.nextInt();
			}
			
			int count = 0;
			Arrays.sort(arr); //, new Comparator<Integer>() {
				
//			});//, Collections.reverseOrder());
			
			System.out.print(arr[n-1]+" ");
			int pre = arr[n-1];
			arr[n-1] = 10001;
			for(int i = n-2; i>= 0; i--)
			{
				int gcd = 1;
				int ansIdx = -1;
//				int max = 0;
//				int maxIdx = -1;
				
				for(int j = n-1; j>= 0; j--)
				{
					if(arr[j] == 10001)
					{
						continue;
					}
					
					int temp = GCD(pre, arr[j]);
					if(temp >= gcd)
					{
						ansIdx = j;
						gcd = temp;
					}
					
//					if(maxIdx == -1 || arr[j]> arr[maxIdx])
//					{
//						maxIdx = j;
//					}
					
				}
				
//				if(ansIdx == -1)
//				{
//					ansIdx = maxIdx;
//				}
				
				System.out.print(arr[ansIdx]+" ");
				pre = gcd;
				arr[ansIdx] = 10001;
			}
			
			System.out.println();
		}
	}
	
	public static int GCD(int a, int b)
	{
//		if(a<b)
//		{
//			return GCD(b, a);
//		}
		if(b==0)
		{
			return a;
		}
		
		return GCD(b, a%b);
	}
}