#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    vector<long long> v(n);
    vector<long long> result(n);
    long long minEle = 1000000000;
    for (int j = 0; j < n; j++) {
      cin >> v[j];
      result[j] = v[j];
      minEle = min(minEle, v[j]);
    }
    sort(result.begin(), result.end());
    bool check = true;
    for (int j = 0; j < n; j++) {
      if (v[j] % minEle != 0 && v[j] != result[j]) {
        check = false;
      }
    }
    if (check) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
