from sys import stdin, stdout

class SOLVE:
    def GCD(self, a, b):
        if a == 0:
            return b
        return self.GCD(b%a, a)
    
    def solve(self):
        R = stdin.readline
        W = stdout.write

        ans = []
        for i in range(int(input())):
            n = int(R())
            a = [int(x) for x in R().split()]
            
            a.sort(reverse = True)
            ans += [str(a[0]) + ' ']
            
            gcd  = a[0]
            a[0] = -1
            for j in range(n-1):
                mx = pos = 0
                for k in range(n):
                    if a[k] != -1:
                        tmp = self.GCD(gcd, a[k])
                        if tmp > mx:
                            mx  = tmp
                            pos = k
                ans   += [str(a[pos]) + ' ']
                a[pos] = -1
                gcd    = mx
            ans += ['\n']

        W(''.join(ans))
    
def main():
    s = SOLVE()
    s.solve()
main()