#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n), b(n);
  long long int mn = 10e9;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    mn = min(mn, a[i]);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i] and b[i] % mn > 0) {
      {
        cout << "NO";
        return;
      }
    }
  }
  cout << "YES";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
}
