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