#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    int m = 2147483647;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] < m) m = a[i];
    }
    vector<int> b = a;
    sort((b).begin(), (b).end());
    int ok = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i] && a[i] % m != 0) {
        ok = 0;
        break;
      }
    }
    if (ok)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
