import math
for _ in range(int(input())):
    x = int(input())
    arr = list(map(int,input().split()))
    mx = max(arr)
    out = [mx]
    arr.remove(mx)
    while arr :
        f = [math.gcd(arr[i],mx) for i in range(len(arr))]
        w = max(f)
        index = f.index(w)
        mx = w
        out.append(arr[index])
        arr.remove(arr[index])
    print(*out)