#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
struct N {
  int first;
  bool second;
  int ind;
};
int main() {
  int k;
  cin >> k;
  while (k--) {
    int n;
    cin >> n;
    N num[n];
    int m;
    int ttmpind;
    for (int i = 0; i < n; i++) {
      cin >> num[i].first;
      if (i == 0) m = num[i].first;
      if (num[i].first > m) {
        m = num[i].first;
        ttmpind = i;
      }
      num[i].second = true;
      num[i].ind = i;
    }
    cout << m << " ";
    num[ttmpind].second = false;
    int tmpm = m;
    int rn = n;
    n -= 1;
    while (n--) {
      int index;
      int mm = 0;
      for (int i = 0; i < rn; i++) {
        if (num[i].second == true) {
          int tmp = gcd(tmpm, num[i].first);
          if (tmp > mm) {
            mm = tmp;
            index = num[i].ind;
          }
        }
      }
      cout << num[index].first << " ";
      num[index].second = false;
      tmpm = mm;
    }
    cout << endl;
  }
}
