#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long maxai = 0;
    multiset<long long> a;
    for (long long i = 0; i < n; i++) {
      long long ai;
      cin >> ai;
      a.insert(ai);
      if (ai > maxai) maxai = ai;
    }
    while (maxai != 1 && a.size()) {
      long long br = 0;
      for (long long i = 1; i <= maxai / 2; i++) {
        if (maxai % i != 0) continue;
        for (long long k = 1; k < 1010; k++) {
          if (k * maxai / i > 1010) break;
          long long count = a.count(k * maxai / i);
          if (count) {
            br = 1;
            for (long long j = 0; j < count; j++) cout << k * maxai / i << ' ';
            a.erase(k * maxai / i);
            maxai = gcd(maxai, k * maxai / i);
            break;
          }
        }
        if (br) break;
      }
      if (!br) break;
    }
    for (multiset<long long>::iterator i = a.begin(); i != a.end(); i++)
      cout << *i << ' ';
    cout << endl;
  }
}
