#include <bits/stdc++.h>
const long long maxn = 9e18;
using namespace std;
const long long maxsize = 100000009;
void solve() {
  int n;
  cin >> n;
  int min_value = 2e9;
  int a[n];
  vector<int> b(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    min_value = min(min_value, a[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] % min_value != 0) b[i] = a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; ++i) {
    if (a[i] % min_value != 0) continue;
    b[i] = a[i];
  }
  for (int i = 1; i < n; ++i) {
    if (b[i] < b[i - 1]) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES	" << endl;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(35);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
