"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""

import math
T=int(input())
for _ in range(0,T):
    n=int(input())
    s=[int(x) for x in input().split()]
    s.sort()
    s=s[::-1]
    L=[s[0]]
    pos=[0]*len(s)
    pos[0] = 1
    curr = s[0]
    for i in range(1,len(s)):
        gd = 1
        ptr=0
        for j in range(0,len(s)):
            if(pos[j]==0):
                tt=math.gcd(s[j], curr)
                if(tt>=gd):
                    gd=tt
                    ptr=j

        L.append(s[ptr])
        pos[ptr]=1
        curr=math.gcd(curr, s[ptr])

    print(*L)
