#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int t, n, a[maxn];
vector<int> v, b;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    int minx = 1e9 + 1;
    v.clear();
    b.clear();
    for (int i = 1; i <= n; i++) cin >> a[i], minx = min(minx, a[i]);
    for (int i = 1; i <= n; i++) {
      if (a[i] % minx == 0) b.push_back(a[i]), v.push_back(i);
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < v.size(); i++) a[v[i]] = b[i];
    bool f = true;
    for (int i = 1; i < n; i++)
      if (a[i] > a[i + 1]) f = false;
    if (f)
      printf("YES\n");
    else
      printf("NO\n");
  }
}
