def gcd(a,b):
    if a == 0:
        return b
    else:
        return gcd(b%a, a)

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    out = [str(max(arr))]
    c = max(arr)
    arr.remove(max(arr))
    while arr != []:
        max_gcd = 0
        max_value = 0
        for i in arr:
            tmp = gcd(i, c)
            if tmp > max_gcd:
                max_gcd = tmp
                max_value = i
        c = max_gcd
        out.append(str(max_value))
        arr.remove(max_value)
    print(' '.join(out))