#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int mex = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] > mex) {
        mex = a[i];
      }
    }
    vector<int> v, u, z;
    for (int i = 0; i < n; i++) {
      if (a[i] == mex) {
        v.push_back(a[i]);
      } else if (mex % a[i] == 0 && a[i] != 1) {
        z.push_back(a[i]);
      } else {
        u.push_back(a[i]);
      }
    }
    for (int i = 0; i < v.size(); i++) {
      cout << v[i] << " ";
    }
    sort(z.begin(), z.end());
    for (int i = 0; i < z.size(); i++) {
      cout << z[i] << " ";
    }
    sort(u.begin(), u.end());
    for (int i = 0; i < u.size(); i++) {
      cout << u[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
