#include <bits/stdc++.h>
using namespace std;
bool isSorted(vector<long long> &v) {
  for (long long i = 1; i < v.size(); i++) {
    if (v[i] < v[i - 1]) return false;
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    long long min_element = INT_MAX;
    for (auto &it : v) {
      cin >> it;
      min_element = min(min_element, it);
    }
    if (isSorted(v)) {
      cout << "YES" << endl;
    } else {
      long long flag = 0;
      vector<long long> values;
      for (long long i = 0; i < v.size(); i++) {
        if (v[i] % min_element == 0) {
          values.push_back(v[i]);
        }
      }
      sort(values.begin(), values.end());
      long long j = 0;
      for (long long i = 0; i < v.size(); i++) {
        if (v[i] % min_element == 0) {
          v[i] = values[j++];
        }
      }
      if (isSorted(v)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  }
}
