#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return 0;
  if (b == 0) return 0;
  if (a == b) return a;
  if (a > b) return gcd(a - b, b);
  return gcd(a, b - a);
}
int main() {
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> v(n);
    for (long long i = 0; i < n; i++) cin >> v[i];
    long long idx = max_element(v.begin(), v.end()) - v.begin();
    long long prevgcd = v[idx];
    v[idx] = 0;
    cout << prevgcd << " ";
    for (int i = 0; i < n - 1; i++) {
      long long m = 0;
      for (int j = 0; j < n; j++) {
        long long temp = gcd(prevgcd, v[j]);
        if (m < temp) {
          m = temp;
          idx = j;
        }
      }
      cout << v[idx] << ' ';
      prevgcd = m;
      v[idx] = 0;
    }
    cout << endl;
  }
  return 0;
}
