# from functools import *
import math
# from collections import *
from sys import stdin, stdout
inp = stdin.readline
out = stdout.write
def mi():
    return map(int,inp().split())
def li():
    return list(mi())
def ii():
    return int(inp())
def main():
    for _ in range(ii()):
        n=ii()
        a=li()
        ans=[]
        ans.append(max(a))
        a.remove(max(a))
        ggcd = ans[0]
        for _ in range(n-1):
            m=-float("inf")
            v=None
            for i in a:
                temp = math.gcd(ggcd,i)
                if temp > m:
                    m=temp
                    v=i
            ans.append(v)
            a.remove(v)
            ggcd = math.gcd(ggcd, v)
        print(*ans)
                
            

if __name__ == "__main__":
    main()