#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long int gcd(long long int a, long long int b) {
  while (true) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    long long int p = b % a, q = a;
    a = p;
    b = q;
  }
}
long long int powerMod(long long int x, long long int y) {
  long long int res = 1;
  x %= 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
string binary(long long int s) {
  string res = "";
  while (s != 0) {
    res += (char)('0' + s % 2);
    s /= 2;
  }
  reverse(res.begin(), res.end());
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  long long int b[n];
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  bool ok = 1;
  for (long long int i = 0; i < n; ++i) {
    if (a[i] != b[i]) {
      if (a[i] % b[0] != 0) {
        ok = 0;
        break;
      }
    }
  }
  if (ok)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
