#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> v(n), a(n);
    long long mi = INT_MAX;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      a[i] = v[i];
      mi = min(mi, v[i]);
    }
    sort(a.begin(), a.end());
    int f = 1;
    for (int i = 0; i < n; i++) {
      if (v[i] != a[i]) {
        if (v[i] % mi != 0) {
          f = 0;
          break;
        }
      }
    }
    if (f)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  int xx;
  cin >> xx;
  return 0;
}
