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