#include <bits/stdc++.h>
using namespace std;
int main() {
  int n_sets;
  cin >> n_sets;
  for (int set_number = 0; set_number < n_sets; set_number++) {
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int min_value = *min_element(a, a + n);
    vector<int> t;
    for (int i = 0; i < n; i++)
      if (a[i] % min_value == 0) {
        t.push_back(a[i]);
        a[i] = 0;
      }
    sort(begin(t), end(t));
    for (int i = 0, j = 0; i < n; i++)
      if (a[i] == 0) a[i] = t[j++];
    bool is_possible = true;
    for (int i = 1; i < n && is_possible; i++) is_possible = a[i - 1] <= a[i];
    cout << (is_possible ? "YES" : "NO") << endl;
  }
  return 0;
}
