#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
string to_string(char c) { return string(1, c); }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(vector<bool> v) {
  string res;
  for (int i = (0); i < ((int)(v).size()); ++i) res += char('0' + v[i]);
  return res;
}
template <size_t SZ>
string to_string(bitset<SZ> b) {
  string res;
  for (int i = (0); i < (SZ); ++i) res += char('0' + b[i]);
  return res;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); }
const long long MOD = 1e9 + 7;
const int MX = 1e5 + 5;
int tree[1];
int sum(int k) {
  int a = 0;
  while (k >= 1) {
    a += tree[k];
    k -= k & -k;
  }
  return a;
}
void add(int k, int x) {
  while (k <= MX) {
    tree[k] += x;
    k += k & -k;
  }
}
vector<int> adj[MX];
int depth[MX];
int diam;
int dfs(int u, int p) {
  int len = 0;
  for (int& v : adj[u])
    if (v != p) {
      depth[v] = depth[u] + 1;
      int cur = 1 + dfs(v, u);
      ckmax(diam, cur + len);
      ckmax(len, cur);
    }
  return len;
}
int dp[205][205][205] = {0};
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  vector<int> flag(a.size(), 0);
  int cur = a[0];
  cout << a[0] << " ";
  for (int i = 1; i < n; ++i) {
    int max_idx = 0;
    int max_v = 0;
    for (int j = 1; j < n; ++j)
      if (!flag[j]) {
        if (max_v < gcd(cur, a[j])) {
          max_v = gcd(cur, a[j]);
          max_idx = j;
        }
      }
    cur = gcd(cur, a[max_idx]);
    cout << a[max_idx] << " ";
    flag[max_idx] = 1;
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
