#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long mn = a[0];
  for (long long i = 0; i < n; i++) {
    mn = min(mn, a[i]);
  }
  vector<long long> b = a;
  sort((b).begin(), (b).end());
  bool ok = true;
  for (long long i = 0; i < n; i++) {
    if (a[i] == b[i]) continue;
    ok &= (a[i] % mn == 0);
  }
  if (ok) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
