import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

import math
from functools import reduce

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
#print(sorted(list(factors(72)),reverse=True))
def gift():
    for _ in range(t):
        n = int(input())
        arry = list(map(int,input().split()))
        arry.sort(reverse = True)
        start = arry[0]
        ans = [start]
        lst = sorted(list(factors(start)),reverse=True)
        index = 1
        arry.remove(start)
        currmax = start
        while index<=n-1:
            found = False
            for ele in lst:
                if ele<=currmax:
                    for aryelement in arry:
                        if aryelement % ele==0:
                            found = True
                            currmax = ele
                            toremove = aryelement
                            break
                if found:
                    break
            ans.append(toremove)
            arry.remove(toremove)
            lst = sorted(list(factors(toremove)),reverse=True)
            index += 1
                
        yield " ".join(str(x) for x in ans)

if __name__ == '__main__':
    t= int(input())
    ans = gift()
    print(*ans,sep='\n')
            


#"{} {} {}".format(maxele,minele,minele)
#1 0 1 0 1 0
