import io
import os

from collections import Counter, defaultdict, deque

from math import gcd


def solve(N, A):
    A.sort()
    ans = [A.pop()]
    while A:
        best = (0,)
        for i, x in enumerate(A):

            best = max(best, (gcd(ans[-1], x), i))
        ans.append(A.pop(best[1]))
    return " ".join(map(str, ans))


if __name__ == "__main__":
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

    TC = int(input())
    for tc in range(1, TC + 1):
        (N,) = [int(x) for x in input().split()]
        A = [int(x) for x in input().split()]
        ans = solve(N, A)
        print(ans)
