from math import gcd
for _ in range(int(input())):
    lens = int(input())
    arrs = [int(x) for x in input().split()]
    B = []
    g = 0
    while arrs:
        a = max(arrs, key = lambda a:gcd(a, g))
        B.append(a)
        g = gcd(a, g)
        arrs.remove(a)
    print(*B)
