import math

for _ in range(int(input())):
    n = int(input())
    arr = [int(x) for x in input().split()]
    s = []
    maxi = max(arr)
    s.append(maxi)
    arr.remove(maxi)
    g = maxi

    for ___ in range(len(arr)):
        toadd = 0
        diff = math.inf
        for ele in arr:
            if g-math.gcd(g,ele) < diff:
                diff = g-math.gcd(g,ele)
                toadd = ele
        s.append(toadd)
        arr.remove(toadd)
        diff = math.inf
        g = math.gcd(g,toadd)
    print(*s)
    