import sys
read = lambda: sys.stdin.readline().strip()
readi = lambda: map(int, read().split())

def gcd(b): 
    a = m
    while (a != b): 
        if (a > b): 
            a = a - b 
        else: 
            b = b - a 
    return a 

def gcd1(a, b): 
    while (a != b): 
        if (a > b): 
            a = a - b 
        else: 
            b = b - a 
    return a 

for _ in range(int(read())):
    n = int(read())
    nums = list(readi())

    m = max(nums)
    nums.remove(m)
    print(m, end=" ")
    prev_gcd = m
    for i in range(1, n):
        m = max(nums, key=gcd)
        nums.remove(m)
        print(m, end=" ")
        m = gcd1(m, prev_gcd)
        prev_gcd = m
        if m == 1:
            break
    print(" ".join(map(str, nums)))