#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> &a, pair<int, int> &b) {
  if (a.first < b.first) return true;
  if (a.first == b.first) return a.second < b.second;
  return false;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    vector<int> ans;
    ans.push_back(a[n - 1]);
    int gc = a[n - 1];
    unordered_map<int, int> m;
    m[n - 1] = 1;
    while (ans.size() < n) {
      int ma = 0;
      int el = -1;
      for (int i = n - 1; i >= 0; i--) {
        if (m.find(i) == m.end()) {
          int ne = gcd(a[i], gc);
          if (ne > ma) {
            ma = ne;
            el = i;
          }
        }
      }
      gc = ma;
      ans.push_back(a[el]);
      m[el] = 1;
    }
    for (auto &i : ans) cout << i << " ";
    cout << endl;
  }
  return 0;
}
