#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, mn = 2e9, cnt = 0;
  cin >> n;
  pair<int, int> a[n];
  for (auto &i : a) cin >> i.first, mn = min(i.first, mn), i.second = cnt++;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (a[i].second != i) {
      if (a[i].first % mn) {
        cout << "NO" << '\n';
        return;
      }
    }
  }
  cout << "YES" << '\n';
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) solve();
}
