#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(00), cin.tie(0), cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    vector<int> v1;
    vector<int> v2;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    reverse(arr.begin(), arr.end());
    int x = arr[0];
    cout << x << " ";
    for (int i = 1; i < n; i++) {
      if (x % arr[i] == 0) {
        v1.push_back(arr[i]);
      } else {
        v2.push_back(arr[i]);
      }
    }
    for (int i : v1) {
      cout << i << " ";
    }
    for (int i : v2) {
      cout << i << " ";
    }
    cout << endl;
  }
  return 0;
}
