# Author : raj1307 - Raj Singh
# Date   : 08.09.2020
 
from __future__ import division, print_function
import sys

input = sys.stdin.readline 
 
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
    
def main():
    for _ in range(int(input())):
        n=int(input())
        a=[int(x) for x in input().split()]
        f=[0]*(n+5)
 
        a.sort(reverse=True)
 
        ans=[a[0]]
        f[0]=1
        g=a[0]
 
        while len(ans)!=n:
            mx=0
            pos=-1
 
            for i in range(n):
                if f[i]==0:
                    if gcd(g,a[i])>mx:
                        mx=gcd(g,a[i])
                        pos=i
                        
                        
            if pos==-1:
                print(1/0)
                
                
            f[pos]=1
            ans.append(a[pos])
            g=gcd(g,a[pos])
        print(*ans)
main()