#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------



#----------
# Functions
#----------

def gcd(a, b):
    a, b = max(a, b), min(a, b)

    while b > 0:
        a, b = b, a % b

    return a

    
def gcd_collection(a, item):
    val = a[0]
    for ai in a:
        val = min(val, gcd(ai, item))
    return val


# The function that solves the task
def calc(a):
    a.sort()
    max_val = a[-1]
    del a[-1]

    res = [ max_val ]
    cg = max_val

    while a:
        val, pos = 0, 0
        for i, item in enumerate(a):
            v = gcd(item, cg) # correct
# 1. wrong
#            v = item
#            for r in res:
#                v = min(v, gcd(item, r))

# 2. wrong
#            v = gcd_collection(res, item)

            if v > val:
                val = v
                pos = i
        res.append(a[pos])
        cg = val
        del a[pos]


#    while a:
#        val, pos = 0, 0
#        for i, item in enumerate(a):
#            if v > val:
#                val = v
#                pos = i
#        res.append(a[pos])
#        del a[pos]

    return res
        

# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


# Converts a sequence to the space separated string
def seq2str(seq):
    return ' '.join(str(item) for item in seq)


#----------
# Execution start point
#----------

if __name__ == "__main__":
    zzz = get_ints()
    assert len(zzz) == 1
    t = zzz[0]

    for i in range(t):
        zzz = get_ints()
        assert len(zzz) == 1
        n = zzz[0]

        zzz = get_ints()
        assert len(zzz) == n
        a = zzz

        res = calc(a)
        print(seq2str(res))
