#include <bits/stdc++.h>
using namespace std;
double const pi = 3.14159265358979323;
const int mod = 1000000007;
void solve(void);
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int t = 1;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
void solve() {
  int n;
  cin >> n;
  vector<long long> A(n);
  long long temp = 1, t = 0;
  for (int i = 0; i < n; i++) cin >> A[i];
  sort((A).begin(), (A).end());
  reverse((A).begin(), (A).end());
  cout << A[0] << ' ';
  temp = A[0];
  A[0] = 1;
  for (int i = 1; i < n; i++) {
    t = 0;
    for (int j = 1; j < n; j++)
      if (A[j] != -1) {
        if (gcd(temp, A[j]) >= gcd(temp, A[t])) t = j;
      }
    cout << A[t] << ' ';
    temp = gcd(temp, A[t]);
    A[t] = -1;
  }
  cout << '\n';
}
