import sys
import itertools


def gcd(a, b):
    if a == b:
        return a
    else:
        if a < b:
            return gcd(a, b - a)
        else:
            return gcd(a - b, b)


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    for i in range(n):
        s = int(sys.stdin.readline())
        data = [(int(i), int(i)) for i in sys.stdin.readline().split()]
        stack = []
        it = 0
        while data:
            data = sorted(data, reverse=True)
            if data[0][1] == 1:
                break
            print(data[0][1], end=" ")
            answers = []
            for gcd_value, value in itertools.islice(data, 1, len(data)):
                answers.append((gcd(gcd_value, data[0][0]), value))
            data = answers
        for gcd_value, value in data:
            print(value, end=" ")

        print("")
