#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, mn = 1000000000002;
    cin >> n;
    vector<long long int> a, b;
    for (int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      a.push_back(x);
      mn = min(x, mn);
    }
    b = a;
    map<long long int, long long int> mp;
    for (int i = 0; i < n; i++) {
      if (a[i] % mn == 0) mp[i] = 1;
    }
    sort(a.begin(), a.end());
    bool f = true;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i] && mp[i] == 0) f = false;
    }
    if (f)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
