#include <bits/stdc++.h>
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
} _io;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, nb = 0;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b, b + n);
    int d = *min_element(a, a + n);
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i] && a[i] % d != 0) {
        cout << "NO" << '\n';
        nb = 1;
        break;
      }
    }
    if (nb == 0) {
      cout << "YES" << '\n';
    }
  }
}
