#include <bits/stdc++.h>
using namespace std;
int n, a[100001], b[100001], mina = 1000000007;
void query() {
  mina = 1000000007;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
    mina = min(mina, a[i]);
  }
  sort(b + 1, b + n + 1);
  int ok = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i] && a[i] % mina != 0) {
      cout << "NO" << '\n';
      return;
    }
  }
  cout << "YES" << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    query();
  }
  return 0;
}
