import math
for t in range(int(input())):
    n = int(input())
    a = sorted(list(map(int, input().split())))[::-1]
    i = 1
    temp = a[0]
    add = -1
    while i < n:
        maxi = 0
        for j in range(i, n):
            if math.gcd(temp, a[j]) > maxi:
                maxi = math.gcd(temp, a[j])
                add = j
        a[i], a[add] = a[add], a[i]
        temp = maxi
        i += 1
    print(*a)