import sys
input = sys.stdin.readline

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

    m = max(a)
    p = []
    f = []
    i = 1
    while i*i <=m:
        if m%i == 0:
            f.append(i)
            if (m//i)!=i:
                f.append(m//i)
        i+=1
    f.sort()
    seen = {}
    last = 0
    for i in reversed(f):
        if last%i!=0:
            continue
        for j in a:
            if j%i == 0:
                if j in seen and seen[j]!=i:
                    continue
                seen[j] = i
                p.append(j)
                last =i
    print(*p)