import math
ct = input()
for line in range(int(ct)):
    n = input()
    arr = [int(i) for i in input().split()]   
    final = []
    final.append(max(arr))
    arr.remove(max(arr))
    
    gcdCurrent = final[0]
    while len(arr) > 0:
        for i in range(len(arr)):
            test = [math.gcd(gcdCurrent,arr[i]) for i in range(len(arr))]
            final.append(arr[test.index(max(test))])
            gcdCurrent = math.gcd(gcdCurrent,max(test))
            arr.remove(arr[test.index(max(test))])
    final = [str(i) for i in final]
    print(' '.join(final))