#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, s = 0;
    cin >> n;
    vector<long long int> a(n), b(n);
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(a.begin(), a.end());
    for (long long int i = 0; i < n; i++) {
      if (s == 1) break;
      if (a[i] != b[i]) {
        if (a[i] % a[0] != 0 || b[i] % a[0] != 0) {
          s = 1;
          break;
        }
      }
    }
    if (s == 0)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
  return 0;
}
