#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long t, n, i, j, k, tmp, max = 0, pos, gc;
  cin >> t;
  vector<long long> arr, ans, vis;
  for (i = 0; i < t; ++i) {
    cin >> n;
    for (j = 0; j < n; ++j) {
      vis.push_back(0);
      cin >> tmp;
      arr.push_back(tmp);
    }
    sort(arr.begin(), arr.end());
    ans.push_back(arr[n - 1]);
    vis[n - 1] = 1;
    tmp = ans[0];
    for (j = 0; j < n; ++j) {
      max = 0;
      for (k = n - 1; k >= 0; --k) {
        gc = gcd(tmp, arr[k]);
        if (gc > max && vis[k] == 0) {
          pos = k;
          max = gc;
        }
      }
      tmp = max;
      vis[pos] = 1;
      ans.push_back(arr[pos]);
    }
    for (j = 0; j < n; ++j) {
      cout << ans[j] << ' ';
    }
    cout << endl;
    ans.clear();
    arr.clear();
    vis.clear();
  }
  return 0;
}
