#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c;
    for (ll i = 0; i < (n); ++i) {
      cin >> a[i];
      b[i] = a[i];
    }
    int Mn = a[0];
    for (ll i = 0; i < (n); ++i) Mn = min(Mn, a[i]);
    sort(b.begin(), b.end());
    int f = 1;
    for (int i = 0; i < n; i++)
      if (a[i] != b[i]) {
        f = 0;
        c.push_back(a[i]);
      }
    if (f) {
      cout << "YES" << endl;
      continue;
    }
    f = 1;
    int GCD = Mn;
    for (ll i = 0; i < ((int)c.size()); ++i) GCD = gcd(GCD, c[i]);
    if (GCD != Mn) f = 0;
    puts(f ? "YES" : "NO");
  }
  return 0;
}
