import sys
pin = sys.stdin.readline

def GCD(a,b):
    a,b = max(a,b),min(a,b)
    while b: a,b = b,a%b
    return a

for T in range(int(pin())):
    N = int(pin())
    A = [*map(int,pin().split())]
    A = sorted(A)[::-1]
    gcd = A[0]
    for n in range(N):
        mx = (1,0)
        for i,v in enumerate(A):
            mx = max(mx,(GCD(gcd,v),i))
        print(A.pop(mx[1]),end=' ')
        gcd = mx[0]
    print()