#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, e;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int flag = 0;
    int n;
    cin >> n;
    vector<int> a;
    vector<int> b;
    for (int j = 0; j < n; j++) {
      cin >> e;
      a.push_back(e);
      b.push_back(e);
    }
    sort(a.begin(), a.end());
    int mine = a[0];
    for (int j = 0; j < n; j++) {
      if (a[j] % mine == 0 || a[j] == b[j]) {
        continue;
      } else {
        cout << "NO" << endl;
        ;
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      cout << "YES" << endl;
    }
  }
}
