'''Author- Akshit Monga'''
def computeGCD(x, y):
    while (y):
        x, y = y, x % y

    return x
t=int(input())
for _  in range(t):
    n=int(input())
    arr=[int(x) for x in input().split()]
    pivot=max(arr)
    ans=[]
    for i in range(n):
        m=-1
        index=-1
        for j in range(len(arr)):
            # print(m,pivot)
            # print(computeGCD(pivot,arr[j]))
            if computeGCD(pivot,arr[j])>m:
                m=computeGCD(pivot,arr[j])
                index=j
        # print(arr[index])
        ans.append(arr[index])
        pivot=computeGCD(pivot,arr[index])
        arr.pop(index)
    for i in ans:
        print(i,end=" ")
    print()
