
def computeGCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x
    
try:
    for _ in range(int(input())):
        n = int(input())
        arr = [int(ele) for ele in input().split()]
        output = []
        maxele = max(arr)
        arr.remove(max(arr))
        output.append(maxele)

        gcd = dict()
        for i in arr:
            gcd[i] = computeGCD(maxele,i)

        newGcd = sorted(gcd.items(), key = lambda x:x[1], reverse = True)
        ok = dict(newGcd)

        for i in ok:
            output.append(i)
        for i in output:
            print(i, end=" ")

except Exception:
    pass
