#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int MAX = 2010;
const long long mod = 1e9 + 7;
const int MAXLV = 16;
using namespace std;
int t, n;
int v[maxn];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    int m = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      m = min(m, v[i]);
    }
    vector<int> goal;
    goal.assign(v, v + n);
    sort(goal.begin(), goal.end());
    bool ruim = 0;
    for (int i = 0; i < n; i++) {
      if (goal[i] != v[i]) {
        if (goal[i] % m || v[i] % m) {
          ruim = 1;
        }
      }
    }
    if (ruim)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
