#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b)
    return gcd(b, a);
  else if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  int t;
  cin >> t;
  for (int x = 0; x < t; x++) {
    int n;
    cin >> n;
    int arr[n];
    int maxm = INT_MIN;
    int maxi = -1;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] > maxm) {
        maxm = arr[i];
        maxi = i;
      }
    }
    if (n == 1) {
      cout << arr[0] << endl;
      continue;
    }
    int ans[n];
    ans[0] = maxm;
    unordered_set<int> used;
    used.insert(maxi);
    int prev = maxm;
    while (used.size() != n) {
      int ind = -1;
      int maxg = INT_MIN;
      for (int i = 0; i < n; i++) {
        if (used.find(i) != used.end()) continue;
        int gc = gcd(prev, arr[i]);
        if (gc > maxg) {
          maxg = gc;
          ind = i;
        }
      }
      prev = maxg;
      ans[used.size()] = arr[ind];
      used.insert(ind);
    }
    for (int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
