for p in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    a=max(arr)
    ans=[]
    ar=[]
    s=set()
    for d in arr:
        if a%d==0:
            ar.append(d)
    ar.sort(reverse=True)
    for d in ar:
        s.add(d)
    for d in arr:
        if d not in s:
            ar.append(d)
    print(" ".join(list(map(str,ar))))