import math
def get_int():
    return int(input())
def get_int_list():
    return list(map(int, input().split()))
def get_char_list():
    return list(input())

def gcd(x, y):
    if x < y:
        return gcd(y, x)
    
    z = x % y
    if z == 0:
        return y
    else:
        return gcd(y, z)

cases = get_int()
for _ in range(cases):
    n = get_int()
    ints = get_int_list()
    v = max(ints)
    ds = set(ints)
    ds.remove(v)
    result = [v]
    while len(ds) > 0:
        md = 0
        t = None
        for d in ds:
            cd = gcd(v, d)
            if cd > md:
                md = cd
                t = d
        
        v = md
        result.append(t)
        ds.remove(t)
    print(*result)