#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
using PT = pair<T, T>;
using PI = pair<int, int>;
using PL = pair<long, long>;
using PSI = pair<string, int>;
using VI = vector<int>;
using VL = vector<ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;
using VSI = vector<PSI>;
void solve() {
  int n;
  cin >> n;
  VI v(n), _v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    _v[i] = v[i];
  }
  sort((_v).begin(), (_v).end());
  int f = 1;
  for (int i = 0; i < n; i++) {
    if (v[i] != _v[i] && (v[i] % _v[0]) != 0) {
      f = 0;
      break;
    }
  }
  if (1) {
    if (!f)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  } else {
    if (!f)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  };
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
