#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
const long long mod = 1e9 + 7;
const long long inf = 2e18 + 5;
const long long nax = 101010;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = (0); i < (n); i++) cin >> a[i];
  vector<long long> b = a;
  sort(b.begin(), b.end());
  for (long long i = (0); i < (n); i++) {
    if (a[i] != b[i] && a[i] % b[0] != 0) {
      cout << "NO" << '\n';
      return;
    }
  }
  cout << "YES" << '\n';
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
