import math
for _ in range(int(input())):
    n = int(input())
    a = sorted(list(map(int, input().split())), reverse = True)
    n = len(a)
    v = [0]*n
    v[0]= 1
    m = -1
    c = 1
    g = a[0]
    # print(g)
    for j in range(1,n):
        m = -1
        for i in range(j,n):
            if(v[i] == 0):
                z = math.gcd(g,a[i])
                if(z>m):
                    m = z
                    u = i
        g = m
        a[u],a[j] = a[j],a[u]
    #     print(g)
    print(*a)

