#include <bits/stdc++.h>
using namespace std;
template <typename T>
void SWAP(T &_a, T &_b) {
  T t = _a;
  _a = _b;
  _b = t;
}
template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &inp_) {
  for (auto &x : inp_) stream << x << " ";
  stream << "\n";
  return stream;
}
template <typename T, typename T_>
ostream &operator<<(ostream &stream, const pair<T, T_> &inp_) {
  stream << "(" << inp_.first << "," << inp_.second << ") ";
  return stream;
}
template <typename T>
T GCD(T a, T b) {
  T temp;
  while (b > 0) {
    temp = b;
    b = a % b;
    a = temp;
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    long long minele = INT_MAX;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      minele = min(minele, a[i]);
    }
    vector<long long> c = a;
    vector<long long> b;
    for (int i = 0; i < n; i++) {
      if (a[i] % minele == 0) {
        b.push_back(a[i]);
        a[i] = -1;
      }
    }
    sort(b.begin(), b.end());
    int k = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == -1) a[i] = b[k++];
    }
    sort(c.begin(), c.end());
    int eq = 1;
    for (int i = 0; i < n; i++) {
      if (c[i] != a[i]) {
        eq = 0;
        break;
      }
    }
    if (eq)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
