from collections import defaultdict
def gcd(a,b):
    if b==0:
        return a
    else:
        op = gcd(b,a%b)
        return op
for _ in range(int(input())):
    n =int(input())
    ls = list(map(int,input().split()))
    ls = sorted(ls,reverse=True)
    ma =ls[0]
    d = defaultdict(int)
    real =[]
    val =[]
    for i in range(1,len(ls)):
        gc = gcd(ma,ls[i])
        d[ls[i]] = gc
    for key, value in sorted(d.items(), key=lambda item: item[1],reverse=True):
        val.append(value)
        real.append(key)
    for j in range(len(val)-1):
        for l in range(j,len(val)):
            if val[l] == val[j]:
                if real[l]>real[j]:
                    real[l],real[j]=real[j],real[l]
    print(ma,*real)



