def GCD(a,b):
    if(b>a) : a,b = b,a

    while(b!=0):
        a=a%b
        a,b=b,a
    return a

import sys
for _ in range(int(input())):
    n = int(sys.stdin.readline())
    arr = list(map(int,sys.stdin.readline().split()))
    ansarr = []

    k = max(arr)
    ansarr.append(k)
    arr.remove(k)

    arr = sorted(arr, reverse =True)
    
    
    while sum(arr) != 0:
        GCDMAX = []
        for i in arr:
            if i == 0:
                GCDMAX.append(0)
            else:
                GCDMAX.append(GCD(k,i))
        k = max(GCDMAX)
        for i in range(len(arr)):
            if GCDMAX[i] == k:
                ansarr.append(arr[i])
                arr[i] = 0
    print(" ".join(map(str,ansarr)))