#include <bits/stdc++.h>
const int MAXN = 2e5 + 15;
using namespace std;
void solve() {
  int n;
  cin >> n;
  int ax = -1;
  std::vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    ax = max(ax, A[i]);
  }
  sort(A.rbegin(), A.rend());
  std::vector<int> v;
  for (int i = 1; i * i <= ax; i++) {
    if (ax % i == 0) {
      v.push_back(i);
      if (i != ax / i) v.push_back(ax / i);
    }
  }
  std::vector<bool> vis(n, 0);
  sort(v.rbegin(), v.rend());
  int g = ax;
  for (int j = 0; j < v.size(); j++) {
    if (g % v[j] == 0) {
      for (int i = 0; i < n; i++) {
        if (A[i] % v[j] == 0 && vis[i] == 0) {
          cout << A[i] << " ";
          vis[i] = 1;
          g = v[j];
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }
  return 0;
}
