import math

def solve(n,ar):
    ar = sorted(ar, reverse=True)
    curr_gcd = ar[0]
    for i in range(1,n):
        ptr = i
        maxi = 0
        maxi_ind = 0
        while ptr < n:
            if math.gcd(curr_gcd,ar[ptr]) >= maxi:
                maxi = math.gcd(curr_gcd,ar[ptr])
                maxi_ind = ptr
            ptr += 1
        curr_gcd = maxi
        ar[i],ar[maxi_ind] = ar[maxi_ind],ar[i]

    print(" ".join(map(str,ar)))






if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        n = int(input())
        ar = list(map(int,input().split()))

        solve(n,ar)