#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int powe(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
vector<long long int> prime(1001, -1);
vector<vector<long long int>> di(1001);
void cal() {
  long long int i;
  for (i = 2; i < 1001; i++) {
    for (long long int j = i + i; j < 1001; j += i) {
      di[j].push_back(i);
    }
    di[i].push_back(i);
  }
}
void solve() {
  long long int i, j, h, l, r, n, k, w, k1, k2, q;
  cin >> n;
  vector<long long int> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  ;
  sort(v.begin(), v.end(), greater<long long int>());
  priority_queue<long long int> pq;
  for (i = 0; i < n; i++) pq.push(v[i]);
  pq.pop();
  map<long long int, long long int> m;
  vector<long long int> ans;
  ans.push_back(v[0]);
  long long int pre = v[0];
  m[v[0]]++;
  for (i = 1; i < n; i++) {
    long long int flag = 0;
    for (j = di[pre].size() - 1; j >= 0; j--) {
      r = di[pre][j];
      for (k = 1; k < n; k++) {
        if (m[v[k]]) continue;
        if (v[k] % r == 0) {
          ans.push_back(v[k]);
          pre = v[k];
          m[v[k]]++;
          flag = 1;
          break;
        }
      }
      if (flag) break;
    }
    if (flag == 0) {
      while (!pq.empty() && m[pq.top()]) {
        pq.pop();
      }
      if (pq.empty()) break;
      pre = pq.top();
      pq.pop();
    }
  }
  for (i = 1; i < n; i++)
    if (!m[v[i]]) ans.push_back(v[i]);
  for (i = 0; i < n; i++) cout << ans[i] << " ";
  ;
  cout << endl;
}
int main() {
  cal();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int i, j, l, k, t, n;
  cin >> t;
  for (i = 1; i <= t; i++) {
    solve();
  }
}
