from fractions import gcd

def swap(arr, i,j):
    t=arr[i]
    arr[i]=arr[j]
    arr[j]=t

def solve():
    n=int(input())
    arr = sorted(int(v) for v in raw_input().split())
    ans=[arr[-1]]
    arr.pop(-1)
    cg=ans[0]
    for i in range(n-1):
        mxg=0
        idx=-1
        for j in range(len(arr)):
            candg=gcd(cg, arr[j])
            if candg > mxg:
                mxg=candg
                idx=j
        swap(arr, 0, idx)
        ans.append(arr[0])
        arr.pop(0)
        cg=mxg
    print ' '.join(str(v) for v in ans)

t=int(input())
for _ in range(t):
    solve()
