from math import *
from collections import *
for u in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    l.sort(reverse=True)
    x=l[0]
    d=[l[0]]
    for i in range(1,n):
        m=0
        y=l[i]
        for j in range(n):
            if(l[j] not in d):
                if(x%l[j]==0):
                    if(l[j]>m):
                        m=l[j]
                        y=l[j]
        d.append(y)
        x=y
    for i in range(n):
        if(l[i] not in d):
            d.append(l[i])
    k=[]
    for i in d:
        if(i not in k):
            k.append(i)
    print(*k)
