#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, _, k;
int a[N], b[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  for (cin >> _; _; --_) {
    cin >> n;
    for (int i = (1); i <= (n); ++i) cin >> a[i], b[i] = a[i];
    sort(b + 1, b + 1 + n);
    bool f = 1;
    for (int i = (1); i <= (n); ++i) {
      if (b[i] == a[i]) continue;
      f = (a[i] % b[1] == 0);
      if (!f) break;
    }
    if (f)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
