import math
for vishal in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    a.reverse()
    lis=[a[0]]
    gc=a[0]
    del a[0]
    # print(a)
    # for i in range(1,len(a)):
    while len(a)>0:
        elem,gcans=-1,-1
        for i in range(len(a)):
            if gcans<math.gcd(gc,a[i]):
                elem=i
                gcans=math.gcd(gc,a[i])
        lis.append(a[elem])
        gc=math.gcd(gc,a[elem])
        del a[elem]
    print(" ".join(map(str,lis)))