#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int power(long long int x, long long int n, long long int mod) {
  long long int res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << a[0];
    return;
  }
  long long int mgcd = a[0];
  vector<long long int> ans(1, 0);
  set<long long int> ss;
  for (long long int i = 1; i < n; ++i) {
    if (a[i] > mgcd) {
      mgcd = a[i];
      ans[0] = i;
    }
  }
  ss.insert(ans[0]);
  for (int i = 1; i < n; ++i) {
    long long int maxi = 0;
    long long int k = 0;
    for (int j = 0; j < n; ++j) {
      if (ss.count(j)) continue;
      if (k < gcd(max(a[j], mgcd), min(a[j], mgcd))) {
        k = gcd(max(a[j], mgcd), min(a[j], mgcd));
        maxi = j;
      }
    }
    ss.insert(maxi);
    ans.push_back(maxi);
  }
  for (int i = 0; i < ans.size(); ++i) {
    cout << a[ans[i]] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
