#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> v(a, a + n);
  sort(v.begin(), v.end());
  long long int j = v[0];
  long long int t = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != v[i] && a[i] % j > 0) {
      t = 1;
      break;
    }
  }
  if (t)
    cout << "NO"
         << "\n";
  else {
    cout << "YES"
         << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int tt;
  cin >> tt;
  while (tt--) solve();
  return 0;
}
