#include <bits/stdc++.h>
using namespace std;
int t, n, a[1024], cnt[1024], ans[1024][1024];
int main() {
  int i, j;
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i <= 1000; i++) cnt[i] = 0;
    sort(a, a + n);
    for (i = n - 1; i >= 0; i--) {
      for (j = i - 1; j >= 0; j--) {
        if (a[j] != 0 && a[i] % a[j] == 0) {
          ans[a[i]][cnt[a[i]]] = a[j];
          cnt[a[i]]++;
          a[j] = 0;
        }
      }
    }
    for (i = n - 1; i >= 0; i--) {
      if (a[i] != 0) {
        cout << a[i] << " ";
        for (j = 0; j < cnt[a[i]]; j++) cout << ans[a[i]][j] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
