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


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    print(max(a), end=' ')
    now = max(a)
    a.remove(now)

    while n > 1:
        x = -1
        select = a[0]
        for i in range(len(a)):
            if gcd(a[i], now) > x:
                x = gcd(a[i], now)
                select = a[i]
        now = gcd(now, select)
        print(select, end=' ')
        a.remove(select)
        n -= 1
    print()


ct = int(input())
while ct > 0:
    solve()
    ct -= 1

 		 	    	  					  	      	   	