#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
void solve() {
  int n, a[100100];
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  int mn = v[0];
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] != v[i] && a[i] % mn != 0) {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
