# Answer Printing Module
def ans_if_list(ans):

    if isinstance(ans, str):
        return ans

    elif isinstance(ans, int):
        return ans

    else:
        return ' '.join(str(ans[i]) for i in range(len(ans)))

# For various input
def input_list(typ='int'):
    if typ == 'int':
        return list(map(int, input().split()))
    elif typ == 'str':
        return list(input())



from math import gcd as motherfucker

t = int(input())


for q in range(t):
    l = int(input())
    ls = input_list()

    c = None


    if l == 1:
        ans_ls = ls

    elif l == 2:
        ans_ls = [max(ls), min(ls)]

    else:
        ans_ls = list()
        mm = max(ls)
        ans_ls.append(mm)
        ls.remove(mm)
        common = 0

        while True:
            candidate = dict()
            for i in range(len(ls)):
                if len(ans_ls) == 1:
                    a = motherfucker(ans_ls[-1], ls[i])
                    candidate[a] = ls[i]

                else:
                    a = motherfucker(common, ls[i])
                    candidate[a] = ls[i]

            common = max(candidate.keys())
            ans_ls.append(candidate[common])
            ls.remove(candidate[common])

            if len(ans_ls) == l:
                break

    print(ans_if_list(ans_ls))
