#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int tt;
  cin >> tt;
  while (tt--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    long long int m = *min_element(a, a + n);
    long long int b[n];
    for (long long int i = 0; i < n; i++) b[i] = a[i];
    sort(b, b + n);
    long long int f = 0;
    for (long long int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        if (a[i] % m != 0) {
          f = 1;
          break;
        }
      }
    }
    if (f)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
