#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using lint = long long;
int tc, cnt;
int n, k;
pii arr[1001];
int ans[1001];
vector<int> fac;
bool cmp1(const pii &a, const pii &b) {
  if (a.first < b.first)
    return true;
  else
    return false;
}
bool cmp2(const pii &a, const pii &b) {
  if (a.second > b.second)
    return true;
  else
    return false;
}
void factor() {
  fac.clear();
  int half = sqrt(ans[0]);
  for (int i = 1; i <= half; i++) {
    if (ans[0] % i == 0) fac.push_back(i);
  }
  int len = fac.size();
  for (int i = len - 1; i > 0; i--) {
    fac.push_back(ans[0] / fac[i]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tc;
  for (int t = 0; t < tc; t++) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> arr[i].first;
    }
    sort(arr, arr + n, cmp1);
    ans[0] = arr[n - 1].first;
    factor();
    int len = fac.size();
    for (int i = 0; i < n - 1; i++) {
      for (int k = len - 1; k >= 0; k--) {
        if (arr[i].first % fac[k] == 0) {
          arr[i].second = fac[k];
          break;
        }
      }
    }
    sort(arr, arr + n - 1, cmp2);
    cout << ans[0] << ' ';
    for (int i = 0; i < n - 1; i++) cout << arr[i].first << ' ';
    cout << '\n';
  }
  return 0;
}
