from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import random
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))
#sys.setrecursionlimit(1500)
def dict(a):
    d={} 
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d
def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bi.bisect_left(a, x)
    if i != len(a):
        return i
    else:            
        return -1
def main():
    try:
        n=I()
        l=list(In())
        ma=-1
        d={}
        t=[]
        for x in l:
            if d.get(x,-1)!=-1:
                d[x]+=1
            else:
                d[x]=1
                ma=max(x,ma)
        i=2

        ans=[]
        s=set()
        while i<=ma:
            temp=i
            zara=[]
            for x in range(temp,ma+1,temp):
                if d.get(x,-1)!=-1:
                    if d[x]!=0:
                        d[x]=0
                        zara.append(x)
            if len(zara)>1:
                zara.sort()
                for x in zara:
                    ans.append(x)
            elif len(zara)==1:
                ans.insert(0,i)
            i+=1

        ans.reverse()
        if d.get(1,-1)!=-1:
            for x in range(d[1]):
                ans.append(1)
        print(*ans)

    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    for _ in range(I()):main()
    #for _ in range(1):main()