import heapq
import collections


def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if a % b == 0:
        return b
    return gcd(b, a % b)


def solve(n, arr):
    if n == 1:
        return arr
    s = set(arr)
    ans = [max(arr)]
    s.remove(max(arr))
    curr_gcd = max(arr)
    while s:
        gcd_max = -1
        for num in s:
            gcd_max = max(gcd_max, gcd(num, curr_gcd))

        next_num = -1
        for num in s:
            if gcd(num, curr_gcd) == gcd_max:
                next_num = max(next_num, num)
        ans.append(next_num)
        s.remove(next_num)
        curr_gcd = gcd_max
    return ans


if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        n = int(input())
        arr = [*map(int, input().split())]
        print(" ".join(map(str, solve(n, arr))))
