#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n], brr[n];
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
      brr[i] = arr[i];
    }
    long long sm = *min_element(arr, arr + n);
    sort(brr, brr + n);
    bool ans = 1;
    for (int i = 0; i < n; i++) {
      if (arr[i] % sm == 0)
        continue;
      else {
        if (brr[i] != arr[i]) {
          ans = 0;
          break;
        }
      }
    }
    if (ans)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
