from math import gcd

R = lambda:map(int,input().split())

t,  = R()
for _ in range(t):
    n = int(input())
    arr = list(R())
    ans = []
    ci = max(arr)
    while arr:
        curr = max((gcd(ci, val), val) for val in arr)
        arr.remove(curr[1])
        ans.append(curr[1])
        ci = curr[0]
    print(* ans)