#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 1e5 + 5;
const long long int INF = 1e18;
const long int mod = 1e9 + 7;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
template <typename T>
void print(vector<vector<T>> &v) {
  for (vector<T> &vv : v) {
    for (T &i : vv) cout << i << " ";
    cout << '\n';
  }
}
bool isPrime(ll n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (ll i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
ll binpow(ll a, ll b, ll m) {
  a %= m;
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
ll to_int(string str) {
  ll n = str.size(), num = 0;
  for (int i = 0; i < n; i++) {
    num = num * 10 + (str[i] - '0');
  }
  return num;
}
ll gcd(ll a, ll b) {
  if (b % a == 0) return a;
  return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    vector<ll> arr(n);
    ll mn = INF, idx;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] < mn) {
        mn = arr[i];
        idx = i;
      }
      mn = min(arr[i], mn);
    }
    vector<ll> tmp, indices;
    for (int i = 0; i < n; i++) {
      if (gcd(arr[i], mn) == mn) {
        tmp.push_back(arr[i]);
        indices.push_back(i);
      }
    }
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < indices.size(); i++) {
      arr[indices[i]] = tmp[i];
    }
    vector<ll> chk = arr;
    sort(chk.begin(), chk.end());
    if (chk == arr) {
      cout << "YES" << '\n';
      ;
    } else {
      cout << "NO" << '\n';
      ;
    }
  }
}
