#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n, greater<int>());
    int mx = a[0];
    vector<int> fact;
    for (int i = 1; i * i <= mx; i++) {
      if (mx % i == 0) {
        fact.push_back(i);
        if (mx / i != i) fact.push_back(mx / i);
      }
    }
    sort(fact.begin(), fact.end(), greater<int>());
    vector<int> ans;
    ans.push_back(mx);
    for (int i = 0; i < fact.size(); i++) {
      int curr = fact[i];
      for (int j = 1; j <= n - 1; j++) {
        if (a[j] % curr == 0 and a[j] != -1) {
          ans.push_back(a[j]);
          a[j] = -1;
        }
      }
    }
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
