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

t=int(input())
for _ in range(t):
    n=int(input())
    s=list(map(int,input().split()))
    p=max(s)
    curr=p
    while len(s)>0:
        m=0
        num=0
        for i in s:
            if gcd(curr,i)>m:
                m=gcd(curr,i)
                num=i
        print(num,end=" ")
        curr=m
        s.remove(num)
    print()