def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))
    maxx = max(arr)
    arr.remove(maxx)
    c = [maxx]
    crnt_gcd = maxx

    while arr:
        now_gcd,now_ind=0,0 
        for i in range(len(arr)):
            now = gcd(crnt_gcd,arr[i])
            if now>now_gcd:
                now_gcd = now
                now_ind = i
        
        c.append(arr.pop(now_ind))
        crnt_gcd = now_gcd

    c = list(map(str,c))
    print(' '.join(c))