#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> in(n);
    ;
    for (long long int i = 0; i < n; i++) cin >> in[i];
    ;
    vector<long long int> ans;
    sort(in.begin(), in.end());
    long long int g1, g2;
    ans.push_back(in[n - 1]);
    g1 = in[n - 1];
    long long int _t;
    {
      _t = in[0];
      in[0] = in[n - 1];
      in[n - 1] = _t;
    };
    for (int i = 1; i <= n - 1; i++) {
      long long int min_j = i;
      g2 = -inf;
      for (int j = i; j <= n - 1; j++) {
        if (g2 < gcd(g1, in[j])) {
          g2 = gcd(g1, in[j]);
          min_j = j;
        }
      }
      g1 = g2;
      long long int _t;
      {
        _t = in[i];
        in[i] = in[min_j];
        in[min_j] = _t;
      };
      ans.push_back(in[i]);
    };
    for (long long int i = 0; i < n; i++) cout << ans[i] << ' ';
    ;
    cout << "\n";
  }
}
