#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t = 1, ara[100000], sara[10000];
  cin >> t;
  while (t--) {
    long long n, i, m = (1LL << 40), flag = 1, x;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> x;
      ara[i] = x;
      sara[i] = x;
      if (x < m) m = x;
    }
    sort(ara, ara + n);
    for (i = 0; i < n; i++) {
      if (ara[i] != sara[i]) {
        if (ara[i] % m) flag = 0;
      }
    }
    if (flag)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
