#include <bits/stdc++.h>
using namespace std;
const long long mod = 10000007;
const double PI = acos(-1);
const double EPS = 1e-9;
long long traillingZero(long long n) {
  long long res = 0;
  for (long long i = 5; i <= n; i *= 5) {
    res += (n / i);
  }
  return res;
}
long long mpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 1)
    return (a * mpow(a, b - 1));
  else {
    long long h = mpow(a, b / 2);
    return (h * h);
  }
}
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second == b.second)
    return a.first < b.first;
  else
    return a.second < b.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
      cin >> x[i];
    }
    vector<int> y = x;
    sort(y.begin(), y.end());
    bool flag = true;
    for (int i = 0; i < n; i++) {
      if (x[i] % y[0] && x[i] != y[i]) {
        flag = false;
        break;
      }
    }
    if (flag)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}
