import math
n = int(input())

for i in range(n):
    m = int(input())
    nums = [int(x) for x in input().split()]
    maxi = max(nums)
    maxd = max(nums)
    print(maxi, end=' ')

    for j in range(m-1):
        nums.remove(maxi)
        temp = [math.gcd(maxd, x) for x in nums]
        maxd = max(temp)
        maxi = nums[temp.index(maxd)]
        print(maxi, end=' ')
    print()
    

