import sys
input= sys.stdin.buffer.readline

from math import gcd
for _ in range(int(input())):
    
    n = int(input())
    arr =[int(c) for c in input().split()]

    mx = max(arr)
    mxind = max(range(len(arr)), key=lambda x: arr[x])
    ans = [mx]
    arr[mxind] = None
    # print(arr)

    for i in range(n-1):
        currmx = 0
        for j in range(len(arr)):
            if arr[j] is None:
                continue
            gc = gcd(mx,arr[j])
            if gc > currmx :
                currmx = gc
                mxind = j
        ans.append(arr[mxind])
        mx = currmx
        arr[mxind] = None
    
    print(*ans)
        