import math

T = int(input())
for _ in range(T):
    n = int(input())
    x = list(map(int, input().split()))

    x.sort()

    x = x[::-1]

    d = dict()
    for i in range(1, len(x)):
        v = math.gcd(x[0], x[i])
        d.update({
            x[i]: v
        })

    key_list = list(d.keys())
    val_list = list(d.values())

    l = list()
    l.append(x[0])
    print(l[0], end=" ")
    for i in sorted(d.values())[::-1]:
        print(key_list[val_list.index(i)], end=" ")
        key_list.pop(val_list.index(i))
        val_list.pop(val_list.index(i))
    print()