import math
for _ in range(int(input())):
    n = int(input())
    arr = [int(x) for x in input().split()]
    m = max(arr)
    gcd = {}
    for num in arr:
        gcd[num] = math.gcd(m, num)
    ans = sorted(gcd, key=lambda x: gcd[x], reverse=True)
    print(*ans)
