#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, w, ele;
    cin >> n;
    map<int, queue<int> > mp;
    vector<int> vect1, vect2;
    int i, j, k, l;
    int a, b, c;
    int mini = INT_MAX;
    for (i = 0; i < n; i++) {
      cin >> j;
      vect1.push_back(j);
      vect2.push_back(j);
      mini = min(mini, j);
      mp[j].push(i);
    }
    sort(vect2.begin(), vect2.end());
    for (i = 0; i < n; i++) {
      if (vect1[i] == vect2[i])
        continue;
      else if (gcd(vect1[i], vect2[i]) == mini) {
        continue;
      } else if (gcd(vect1[i], mini) == mini)
        continue;
      else
        break;
    }
    if (i == n)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
