fact = dict()
fact[1] = {1}
for i in range(2, 1001):
    fact[i] = set()
    fact[i].add(i)
    for j in range(i//2+1, 0, -1):
        if i%j==0:
            fact[i].add(j)


t = int(input())
while t:
    t-=1
    n = int(input())
    l = list(map(int, input().split()))
    l.sort(reverse=True)
    d = dict()
    for i in l:
        if i not in d:
            d[i] = 1
        else:
            d[i] += 1
    ans = []
    for i in range(d[l[0]]):
        ans.append(l[0])
    inc = set()
    inc.add(l[0])
    num = dict()
    l = set(l)
    l = list(l)
    l.sort(reverse=True)
    for i in l:
        for j in fact[i]:
            if j in num:
                num[j].append(i)
            else:
                num[j] = [i, ]
    # print(num)
    temp = fact[l[0]]
    temp = list(temp)
    temp.sort(reverse=True)
    for i in temp:
        if i in num:
            for j in num[i]:
                if j not in inc:
                    inc.add(j)
                    for k in range(d[j]):
                        ans.append(j)
    for i in l:
        if i not in inc:
            inc.add(i)
            for j in range(d[i]):
                ans.append(i)
    for i in ans:
        print(i, end=' ')
    print()



