#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, p = 0, q = 0, r, i, j;
    cin >> n;
    long long a[n];
    vector<pair<long long, long long>> v;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      v.push_back(make_pair(a[i], i));
    }
    sort(v.begin(), v.end());
    p = a[0];
    for (i = 0; i < n; i++) {
      if (a[i] < p) {
        p = a[i];
      }
    }
    for (i = 0; i < n; i++) {
      if (a[i] != v[i].first) {
        if (a[i] % p != 0) {
          q = 1;
          break;
        }
      }
    }
    if (q == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
