import math
t = int(input())
ans = []
for i in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    t = []
    t.append(a[-1])
    x = a.pop()
    a.reverse()
    while len(a) > 0:
        y = -1
        g = -1
        for j in range(len(a)):
            if g < math.gcd(x, a[j]):
                y = j
                g = math.gcd(x, a[j])
        t.append(a[y])
        x = math.gcd(x, a.pop(y))
    ans.append(" ".join(map(str, t)))
for l in ans:
    print(l)
    		  		  	  	       	 	  		