def gcd(a, b):
    # Everything divides 0
    if (b == 0):
        return a
    return gcd(b, a % b)
for p in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    a=max(arr)
    ans=[]
    ar=[]
    s=set()

    g = max(arr)
    while len(ar)<n:
        ar1=[]
        m=-1
        for d in arr:
            if d not in s and gcd(g,d)>m:
                m=gcd(g,d)
        for d in arr:
            if d not in s and gcd(g,d)==m:
                ar1.append(d)
        ar+=ar1
        for d in ar1:
            s.add(d)
        g=m



    print(" ".join(list(map(str,ar))))