def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
for _ in range(input()):
    n=input()
    a=[int(i) for i  in raw_input().split()]
    maxx=max(a)
    l=[[gcd(i,maxx),i] for i in a]
    l.sort()
    l=l[::-1]
    for i in l:
        print i[1],
    print
