from math import gcd
for _ in range(int(input())):
    n = int(input())
    a = [*map(int,input().split())]
    vis = [0]*n
    last = 0
    for i in range(n):
        last = max(last,a[i])
    for i in range(n):
        if(a[i]==last):
            vis[i] = 1
            break
    print(last,end=" ")
    p = last
    for j in range(1,n):
        maxi,pos = 0,0
        for i in range(n):
            if(vis[i]):
                continue
            if(gcd(p,a[i])>maxi):
                maxi = gcd(p,a[i])
                pos = i
        vis[pos] = 1
        print(a[pos],end=" ")
        p = maxi
    print()