#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int N = 1e5 + 5;
void solve() {
  long long int n;
  scanf("%lld", &n);
  vector<long long int> a(n);
  vector<long long int> b(n);
  for (auto i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    b[i] = a[i];
  }
  sort(a.begin(), a.end());
  long long int m = a[0];
  bool res = true;
  for (auto i = 0; i < n; i++) {
    if (b[i] != a[i]) {
      if (b[i] % m != 0) {
        res = false;
        break;
      }
    }
  }
  if (res)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int main() {
  long long int t = 1;
  scanf("%lld", &t);
  while (t--) {
    solve();
  }
  return 0;
}
