#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t, n, a, b, c, x1, y1, z1, sum, ans, x2, y2, z2, m, ind;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> g(n);
    vector<int> used(n, 0);
    m = 1000000000;
    for (int i = 0; i < int(n); i++) {
      cin >> g[i];
      m = min(m, g[i]);
    }
    vector<int> w;
    for (int i = 0; i < int(n); i++) {
      if (g[i] % m == 0) {
        w.push_back(g[i]);
        used[i] = 1;
      }
    }
    sort(w.begin(), w.end());
    ind = 0;
    for (int i = 0; i < int(n); i++) {
      if (used[i] == 1) {
        g[i] = w[ind];
        ind++;
      }
    }
    ind = 1;
    for (int i = 1; i < n; i++) {
      if (g[i] < g[i - 1]) {
        ind = 0;
      }
    }
    if (ind == 1) {
      cout << "YES";
    } else {
      cout << "NO";
    }
    cout << endl;
  }
}
