def recursor(a):
    result_list = []
    x = max(a)
    a.pop(a.index(x))
    for i in a:
        if x % i == 0:
            result_list.append(i)
    if len(result_list) == 0:
        return [x] + a
    else:
        r = max(result_list)
        a.pop(a.index(r))
        return [x] + [r] + a
    
nstr = int(input())
for i in range(nstr):
    N = int(input())
    M = [int(x) for x in input().split()]
    result = recursor(M)
    print(' '.join([str(x) for x in result]))