import math
import os
import random
import re
import string
from sys import *
from collections import *
#"Case #"+str(_+1)+":"+" "+str(c)
#l=list(map(int,stdin.readline().strip().split()))
def find_gcd(x,y):
    a,b=x,y
    while y:
        x,y=y,x%y

    lcm=int((a*b)/x)
    #return lcm
    return x
#lcm and hcf is optional whichever we need 

'''a,b=map(int,input().strip().split())
result=find_gcd(a,b)
print(result)'''
'''l=list(map(int,input().strip().split()))
num1=l[0]
num2=l[1]
gcd=find_gcd(num1,num2)
for i in range(2,len(l)):
    gcd=find_gcd(gcd,l[i])
print(gcd)'''
def bs(arr,x,l,r):
    if l<=r:
        mid=(r+l)//2
        if arr[mid]==x:
            return mid
        elif arr[mid]>x:
            return bs(arr,x,l,mid-1)
        else:
            return bs(arr,x,mid+1,r)
    else:
        return -1
def solve():
    for _ in range(int(input())):
        n=int(input())
        l=list(map(int,stdin.readline().strip().split()))
        res=[max(l)]
        rr=max(l)
        l.remove(max(l))
        while len(l)>0:
            ma=0
            for j in range(len(l)):
                a=find_gcd(l[j],rr)
                if a>=ma:
                    ma=a
                    r=l[j]
            rr=ma
            res.append(r)
            l.remove(r)
        print(*res)
            
        
if __name__=="__main__":
    solve()
