from math import gcd as _gcd
import sys as _sys


def main():
    t = int(input())
    for i in range(t):
        n, = _read_ints()
        a = tuple(_read_ints())
        b = find_b(a)
        print(*b)


def _read_line():
    result = _sys.stdin.readline()
    assert result[-1] == "\n"
    return result[:-1]


def _read_ints():
    return map(int, _read_line().split(" "))


def find_b(a):
    a = list(a)
    b = []
    if len(a) == 0:
        return b
    first_element = max(a)
    b.append(first_element)
    a.remove(first_element)
    curr_gcd = first_element
    while len(a) != 0:
        next_element = max(a, key=lambda x: _gcd(curr_gcd, x))
        b.append(next_element)
        a.remove(next_element)
        curr_gcd = _gcd(curr_gcd, next_element)
    return b


if __name__ == '__main__':
    main()
