#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 1001;
int a[kMaxN], b[kMaxN];
int t, n, m;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    m = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      m = max(m, a[i]);
    }
    fill(b, b + n, 1);
    for (int i = m; i >= 1; i--) {
      if (m % i == 0) {
        for (int j = 0; j < n; j++) {
          if (b[j] && a[j] % i == 0) {
            cout << a[j] << " ";
            b[j] = 0;
          }
        }
      }
    }
    cout << endl;
  }
  return 0;
}
