#include <bits/stdc++.h>
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;
const int N = 1e6 + 9;
const int M = 2e3 + 9;
const int INFINT = 1e9 + 9;
const long long INFLL = 1e18 + 9;
const long long MOD = (long long)(1000000007);
void solve() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < (int)n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  int mn = *min_element(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int i = 0; i < (int)n; ++i) {
    if (a[i] % mn != 0 && a[i] != b[i]) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
