#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto& x : v) cin >> x;
  if (n == 1) {
    cout << "YES" << '\n';
    return;
  }
  if (is_sorted(v.begin(), v.end())) {
    cout << "YES" << '\n';
    return;
  }
  vector<int> chk(v.begin(), v.end());
  sort(v.begin(), v.end());
  auto m = *min_element(v.begin(), v.end());
  vector<int> ans;
  for (int i(0); i < n; ++i) {
    if (chk[i] != v[i]) ans.emplace_back(i);
  }
  int cnt = 0;
  for (auto x : ans) {
    if (v[x] % m == 0) cnt++;
  }
  if (cnt == ans.size())
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  for (int i(1); i <= t; ++i) {
    solve();
  }
  return 0;
}
