#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxN = 1e6 + 5;
const long long N = 1e6;
long long n;
long long a[maxN], b[maxN];
void solve() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) b[i] = a[i];
  sort(b + 1, b + 1 + n);
  vector<long long> v;
  for (long long i = 1; i <= n; i++)
    if (a[i] != b[i]) v.push_back(a[i]);
  long long minn = 1e18;
  for (long long i = 1; i <= n; i++) minn = min(minn, a[i]);
  for (auto t : v) {
    if (t % minn != 0) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long T;
  cin >> T;
  while (T--) solve();
  return 0;
}
