#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Gcd(ll a, ll b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  ll t, tst = 0;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n, greater<ll>());
    ll pos = 0, pres = a[0];
    for (ll i = 1; i < n; i++) {
      ll mx = 0;
      for (ll j = i; j < n; j++) {
        ll GCD = Gcd(pres, a[j]);
        if (mx < GCD) {
          mx = GCD;
          pos = j;
        }
      }
      swap(a[i], a[pos]);
      pres = mx;
    }
    for (ll i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
  }
}
