import math
for t in range(int(input())):
    n=int(input())
    num=list(map(int,input().split()))
    num.sort()
    val=num.pop()
    out=[val]
    while num:
        gcd=0
        ele=0
        for i in range(len(num)):
            v=math.gcd(val,num[i])
            if v>gcd:
                gcd=v
                ele=i
        val=gcd
        out.append(num.pop(ele))
    print(*out)