from math import gcd
for _ in range(int(input())):
    n = int(input())
    l =list(map(int,input().split()))
    if len(l) == 1:
        print(l[0])
        continue
    g = [[gcd(l[i],l[j]) for j in range(n)] for i in range(n)]
    for i in range(n):
        g[i][i] = -1
    maxm = max(l)
    gg = int(maxm)
    
    left = [i for i in range(n)]
    left.remove(l.index(maxm))
    b = [maxm]
    while len(left) > 0:
        maxm = 0
        ans = -1
        for k in left:
            if gcd(l[k],gg) > maxm:
                maxm = int(gcd(l[k],gg))
                ans = int(k)
        b.append(l[ans])
        left.remove(ans)
        gg = int(maxm)
    print(' '.join(map(str,b)))