#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << '>' << #x << ": " << x << " [" << __LINE__ << "]\n";
const double E = 1e-8;
long long comp;
void solve();
bool compare(long long a, long long b);
int main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   int TEST_CASE=1;
   cin>>TEST_CASE;
   while(TEST_CASE--)
   {
      solve();
      cout<<"\n";
   }

   cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}
bool compare(long long a, long long b) {
   return gcd(comp, a) > gcd(comp, b);
}
void solve()
{
   int n, i;
   cin >> n;
   vector<long long> num(n);
   for (i = 0; i < n; i++) {
      cin >> num[i];
      if (!i) {
         comp = num[i];
      }
      else {
         comp = max(comp, num[i]);
      }
   }
   sort(num.begin(), num.end(), compare);
   for (i = 0; i < n; i++) {
      cout << num[i] << " ";
   }
}
