#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n], a[n];
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    vector<long long> indices, values;
    long long mini = *min_element(arr, arr + n);
    for (long long i = 0; i < n; i++) {
      if (arr[i] % mini == 0) {
        indices.push_back(i);
        values.push_back(arr[i]);
      }
    }
    sort(values.begin(), values.end());
    long long flag = 0;
    for (long long i = 0; i < values.size(); i++) {
      arr[indices[i]] = values[i];
    }
    for (long long i = 0; i < n - 1; i++) {
      if (arr[i] > arr[i + 1]) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      cout << "NO"
           << "\n";
    } else {
      cout << "YES"
           << "\n";
    }
  }
  return 0;
}
