from math import gcd


if __name__ == "__main__":
    for _ in range(int(input())):
        n = int(input())
        num = list(map(int, input().split()))
        index = num.index(max(num))
        result = [num[index]]
        num[index] = -1

        value = result[0]
        for i in range(1, n):
            max_value = -1
            index = -1
            for j in range(n):
                if num[j] == -1:
                    continue
                else:
                    temp = gcd(value, num[j])
                    if temp > max_value:
                        max_value = temp
                        index = j

            value = gcd(value, num[index])
            result.append(num[index])
            num[index] = -1
        print(" ".join(map(str, result)))
