from collections import defaultdict
import math
t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    final = [max(l)]
    done = defaultdict(int)
    for j in range(n):
        done[l[j]]+=1
    val = final[0]
    done[final[0]]-=1
    for j in range(1,n):
        maximum = 0
        number = 0
        for k in range(n):
            gcd = math.gcd(l[k],val)
            if(done[l[k]]!=0 and gcd>=maximum):
                maximum = gcd
                number = l[k]
        final.append(number)
        done[number] -= 1
        val = maximum
    # print(done)
    print(*final,sep=' ')




