# map(int, input().split())
rw = int(input())
for wewq in range(rw):
    n = int(input())
    astr = list(input().split())
    astr.sort()
    astr.reverse()
    maxlen = len(astr[0])
    m = 0
    for i in range(len(astr)):
        if len(astr[i]) > maxlen:
            maxlen = len(astr[i])
            m = i
    aint = list(map(int, astr))
    b = [astr[m]]
    ai = int(astr[m])
    astr.pop(m)
    for i in astr:
        if ai % int(i) == 0:
            astr.remove(i)
            b.append(i)
    for i in astr:
        b.append(i)
    for i in b:
        print(i, end = ' ')
    print(' ')




