from math import gcd

for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    l.sort()
    l.reverse()
    sol = []
    sol.append(l[0])
    g = l[0]
    del l[0]
    while len(l)>0:
        tg = -1
        ind = -1
        for i in range(len(l)):
            ttg = gcd(g, l[i])
            if ttg>tg:
                ind = i
                tg = ttg
        g = tg
        sol.append(l[ind])
        del l[ind]
    print(' '.join([str(i) for i in sol]))