import sys
sys.setrecursionlimit(10**6)
from collections import Counter,defaultdict as dft
def mp():return map(int,input().split())
def ml():return list(map(int,input().split()))


def solve():
    
    n=int(input())
    arr=ml()
    vis=[0]*(n+5)
    #print(fac)
    arr.sort(reverse=True)
    res=[]
    
    for p in range(10**3+1,0,-1):
        case=0
        for i in range(len(res)):
            if res[i]%p!=0:
                case=1
                break
        if case:
            continue
        for i in range(n):
            if vis[i]==0 and arr[i]%p==0:
                res.append(arr[i])
                vis[i]=1
      
    print(*res)
    
    
    


t=int(input())

for _ in range(t):
    solve()
    #pass
