from math import gcd
for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    ci = max(a)
    fin = []
    while a:
        curr = max((gcd(ci,val),val) for val in a)
        a.remove(curr[1])
        fin.append(curr[1])
        ci = curr[0]
    print(*fin)
