#include <bits/stdc++.h>
using namespace std;
void solveTestCases() {
  long long n;
  cin >> n;
  std::vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  unordered_map<long long, long long> mp;
  cout << a[0] << " ";
  for (long long i = 1; i < n; i++) {
    if (a[0] % a[i] == 0) {
      cout << a[i] << " ";
      mp[a[i]]++;
    }
  }
  for (long long i = 1; i < n; i++) {
    if (mp.find(a[i]) == mp.end()) cout << a[i] << " ";
  }
  cout << endl;
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long TESTCASES;
  cin >> TESTCASES;
  while (TESTCASES--) solveTestCases();
  return 0;
}
