#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, a, min, flag = 1;
  cin >> n;
  vector<long long int> v, v1, t;
  for (long long int i = 0; i < n; ++i) {
    cin >> a;
    v.push_back(a);
    v1.push_back(a);
  }
  sort(v1.begin(), v1.end());
  min = v1[0];
  for (long long int i = 0; i < n; ++i) {
    if (v[i] % min == 0) {
      t.push_back(1);
    } else {
      t.push_back(0);
    }
  }
  for (long long int i = 0; i < n; ++i) {
    flag = 1;
    if (v[i] != v1[i]) {
      if (t[i] == 0) {
        flag = 0;
        break;
      }
    }
  }
  if (flag == 1) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
    if (t) cout << "\n";
  }
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  return 0;
}
