from math import gcd as GCD

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

    n = int(input())
    ar = list(map(int, input().split()))
    checked = [False]*n

    rem, mx = -1, 0
    for idx, num in enumerate(ar):
        if num>mx:
            mx = num
            rem = idx
    checked[rem] = True
    gcd = mx
    print(mx, end=" ")

    for i in range(n-1):
        rem, var = -1, 0
        for idx, num in enumerate(ar):
            if not checked[idx] and GCD(gcd,num)>var:
                var = GCD(gcd,num)
                rem = idx
        checked[rem] = True
        gcd = var
        print(ar[rem], end=" ")
    print()