#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const ll mod = 1e9 + 7;
using namespace std;
const int N = 1e6 + 5;
ll a[N], b[N], m, n, t, k, T, ans, res;
string s1, s2;
vector<ll> p;
inline void sol() {
  cin >> T;
  while (T-- > 0) {
    cin >> n;
    bool check = true;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    for (int i = 1; i <= n; i++) {
      if (a[i] != b[i] && a[i] % b[1] != 0) {
        check = false;
        break;
      }
    }
    if (check)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("matrix"
            ".inp",
            "r")) {
    freopen(
        "matrix"
        ".inp",
        "r", stdin);
    freopen(
        "matrix"
        ".out",
        "w", stdout);
  }
  sol();
}
