#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1000000007;
int cg(int a, int b) {
  while (b != 0) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}
void solve() {
  int n, gc;
  cin >> n;
  vector<int> a(n), b;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  b.push_back(a[0]);
  gc = a[0];
  multiset<int> s;
  for (int i = 0; i < n - 1; i++) s.insert(a[i + 1]);
  while ((int)s.size()) {
    auto it = s.begin();
    int k, l = 1, m = 1;
    while (it != s.end()) {
      int u = cg(*it, gc);
      if (l < u) {
        l = u;
        k = *it;
      }
      it++;
    }
    gc = l;
    if (gc == 1) break;
    b.push_back(k);
    s.erase(s.find(k));
  }
  auto it = s.begin();
  while (it != s.end()) {
    b.push_back(*it);
    it++;
  }
  for (int i = 0; i < n; i++) cout << b[i] << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
