from math import gcd
for _ in range(int(input())):
    n = int(input())
    arr = [int(num) for num in input().split(' ')]
    a = max(arr)
    ans = [a]
    c = [a]
    arr.remove(a)
    while len(c)<=n-1:
        x = []
        for item in arr:
            x.append([gcd(c[-1],item),item])
        x.sort(key = lambda x:x[0],reverse=True)
        c.append(x[0][0])
        arr.remove(x[0][1])
        ans.append(x[0][1])
    for item in ans:
        print(item,end=' ')
    print('')