from sys import stdin
input = stdin.buffer.readline
def computeGCD(x, y):
    while y:
        x, y = y, x % y

    return x

def func():
    final = [a[0], ]
    a[0] = -1

    for i in range(n):
        ind = -1
        num = 1
        for j in range(1, n):
            if a[j] != -1:
                temp = computeGCD(final[-1], a[j])
                # print(f'{final[-1]=} {a[j]=} {temp}')
                # print(f'{num=} {temp=} {ind=}')
                if num < temp:
                    ind = j
                    num = temp
        # print('final', final)
        if ind != -1:
            # print('append', a[ind])
            final.append(a[ind])
            a[ind] = -1
        else:
            break
    for k in a:
        if k != -1:
            final.append(k)

    print(*final)
    # print(a)




for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    func()
