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

T = int(input())
for __ in range(T):
    n = int(input())
    nums = list(map(int, input().split()))
    cnt = {}
    for num in nums:
        cnt[num] = cnt.get(num, 0) + 1
    ret = []
    curr = None
    while cnt:
        chosen = max(cnt, key=lambda x: gcd(x, curr)) if curr else max(cnt)
        if cnt[chosen] == 1:
            cnt.pop(chosen)
        else:
            cnt[chosen] -= 1
        ret.append(chosen)
        curr = gcd(curr, chosen) if curr else chosen
    print(' '.join(map(str, ret)))