#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int i, j, k, n, m = 1e10, f = 1;
    cin >> n;
    vector<long long int> a(n), b(n), in, val;
    for (i = 0; i < n; i++) {
      cin >> a[i], b[i] = a[i];
      m = min(a[i], m);
    }
    sort(b.begin(), b.end());
    for (i = 0; i < n; i++)
      if (a[i] % m == 0) in.emplace_back(i), val.emplace_back(a[i]);
    sort(val.begin(), val.end());
    for (i = 0; i < in.size(); i++) a[in[i]] = val[i];
    for (i = 0; i < n; i++)
      if (a[i] != b[i]) {
        f = 0;
        break;
      }
    if (f)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
