#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    long long int ar[10000];
    cin >> n;
    long long int a[10000], q[100000];
    memset(ar, 0, sizeof(ar));
    memset(q, 0, sizeof(q));
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      q[a[i]]++;
    }
    long long int max = -1, ans[10000];
    sort(a + 1, a + n + 1, greater<long long int>());
    ans[1] = a[1];
    int k = 2;
    long long int re, y = a[1], f = 0;
    long long int c = a[1];
    ar[1]++;
    re = 1;
    for (int i = 1; i <= n; i++) {
      max = -1;
      if (k <= n) {
        for (int j = 1; j <= n; j++) {
          long long int x;
          if (ar[j] != 1) {
            x = gcd(y, a[j]);
            if (x >= max) {
              max = x;
              re = j;
              f = j;
            }
          }
        }
        y = max;
        ans[k] = a[re];
        k++;
        ar[re]++;
        re = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
}
