from collections import defaultdict
from math import gcd

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    arr.sort(reverse=True)

    take = defaultdict(lambda: False)
    take[0] = True
    ans = list()
    ans.append(arr[0])
    for i in range(1, n):
        idx, maxx, flag = i, 1, False
        for j in range(n):
            if take[j] or i == j:
                continue
            
            g = gcd(ans[-1], arr[j])
            if g >= maxx:
                maxx = g
                idx = j
                flag = True
        ans.append(arr[idx])
        take[idx] = True

    print(*ans)