#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  long long int x1, y1, z1, x2, y2, z2;
  cin >> t;
  long long int n;
  while (t--) {
    cin >> n;
    long long int mn = 1e9;
    vector<pair<long long int, long long int>> v(n);
    long long int prev;
    int y = 1;
    for (int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      if (i == 0) {
        v[i] = make_pair(x, i);
      } else {
        v[i] = make_pair(x, i);
        if (x < prev) {
          y = 0;
        }
      }
      mn = min(mn, x);
      prev = x;
    }
    if (y)
      cout << "YES"
           << "\n";
    else {
      sort((v).begin(), (v).end());
      int z = 1;
      for (int i = 0; i < n; i++) {
        if ((v[i].first % mn) != 0 && (v[i].second) != i) {
          z = 0;
          break;
        }
      }
      if (z)
        cout << "YES"
             << "\n";
      else
        cout << "NO"
             << "\n";
    }
  }
}
