import sys
import math
def main():
    pass
def binary(n):
    return (bin(n).replace("0b", ""))
def decimal(s):
    return (int(s, 2))
def pow2(n):
    p = 0
    while n > 1:
        n //= 2
        p += 1
    return (p)
def isPrime(n):
    if (n == 1):
        return (False)
    else:
        root = int(n ** 0.5)
        root += 1
        for i in range(2, root):
            if (n % i == 0):
                return (False)
        return (True)

def sinp(): return sys.stdin.readline().strip()
def iinp(): return int(input())
def ninp(): return map(int, sys.stdin.readline().strip().split())
def linp(): return list(map(int, sys.stdin.readline().strip().split()))
def p(a): print(a)

for _ in range(iinp()):
    n=iinp()
    a=linp()
    a.sort()
    a.reverse()
    m=a[0]
    l1=[]
    gcd=m
    ind=0
    freq=[0]*1005
    for i in a:
        freq[i-1]+=1
    for i in range(1,m+1):
        if (m % i == 0):
            l1.append(i)
    l1.reverse()
    for i in a:
        gcd=math.gcd(m,i)
        ind=l1.index(gcd)
        l1.insert(ind,i)
    for i in l1:
        if(freq[i-1]>0):
            print(i,end=" ")
            freq[i-1]-=1
    print("")


