import math
cases = int(input())
for t in range(cases):
    n = int(input())
    a = list(map(int,input().split()))
    a = sorted(a)[::-1]
    v1 = a[0]
    for i in range(n-2):
        mv = 0
        pos = -1
        v1 = math.gcd(v1,a[i])
        for j in range(i+1,n):
            v = math.gcd(v1,a[j])
            if v>mv:
                mv=v
                pos=j
        if pos>i:
            a[i+1],a[pos]=a[pos],a[i+1]
    print(*a)