#include <bits/stdc++.h>
using namespace std;
bool solve() {
  int n;
  cin >> n;
  int a[n];
  for (auto &i : a) cin >> i;
  if (n == 1) return 1;
  int b[n];
  for (int i = 0; i < n; i++) b[i] = a[i];
  sort(b, b + n);
  vector<int> v;
  int mini = b[0];
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i] && a[i] % mini != 0) return 0;
  }
  return 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cout << (solve() ? "YES" : "NO") << "\n";
  }
  return 0;
}
