import math

def main(A,n):
    res = []
    val = max(A)
    res.append(val)
    A.remove(val)
    pre_gcd = val
    flag = 'Notfound'
    while A != []:
        max_gcd = 0
        for i in A:
            cur_gcd = math.gcd(pre_gcd,i)
            if cur_gcd > max_gcd:
                max_gcd = cur_gcd
                val = i
                flag = 'found'        
        if flag == 'Notfound':
            A.remove(i)
            res.append(i)
        else:    
            A.remove(val)
            res.append(val)
            pre_gcd = max_gcd
    return 	res				
if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        n = int(input())
        A = list(map(int,input().split()))
        val = main(A,n)
        print(*val)