#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC target("sse4")
using namespace std;
vector<int> divs[(long long)(1e3 + 5)];
void criba() {
  for (int i = 1; i < (long long)(1e3 + 5); i++)
    for (int j = i; j < (long long)(1e3 + 5); j += i) divs[j].push_back(i);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  criba();
  for (int i = 0; i < (long long)(1e3 + 5); i++)
    reverse((divs[i]).begin(), (divs[i]).end());
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> fs((long long)(1e3 + 5));
    int ma = 0;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      fs[x]++;
      ma = max(ma, x);
    }
    vector<int> res;
    for (int i = 0; i < fs[ma]; i++) res.push_back(ma);
    fs[ma] = 0;
    int x = ma;
    while (1) {
      int nex = -1;
      for (auto d : divs[x]) {
        int sum = 0;
        for (int i = d; i < (long long)(1e3 + 5); i += d) sum += fs[i];
        if (sum) {
          nex = d;
          break;
        }
      }
      if (nex == -1) break;
      for (int i = nex; i < (long long)(1e3 + 5); i += nex) {
        for (int j = 0; j < fs[i]; j++) res.push_back(i);
        fs[i] = 0;
      }
      x = nex;
    }
    for (int i = 0; i < n; i++) cout << res[i] << ' ';
    cout << '\n';
  }
  return 0;
}
