#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    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 k = *min_element(a, a + n);
    bool bl = true;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i] && a[i] % k) {
        bl = false;
        break;
      }
    }
    if (bl)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
