#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int array[n];
    long long int minValue = INT_MAX;
    for (long long int i = 0; i < n; i++) {
      cin >> array[i];
      minValue = min(minValue, array[i]);
    }
    vector<long long int> v;
    for (long long int i = 0; i < n; i++) {
      if ((array[i] % minValue) == 0) {
        v.push_back(array[i]);
        array[i] = 0;
      }
    }
    long long int len = v.size();
    int arr[len];
    for (int i = 0; i < len; i++) arr[i] = v[i];
    sort(arr, arr + len);
    int j = 0;
    for (long long int i = 0; i < n; i++) {
      if (array[i] == 0) {
        array[i] = arr[j];
        j++;
      }
    }
    long long int flag = 1;
    for (long long int i = 1; i < n; i++) {
      if (array[i] < array[i - 1]) {
        flag = 0;
      }
    }
    if (flag) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
