#include <bits/stdc++.h>
using namespace std;
const long long N = 2100000;
long long mod = 1e9 + 7;
int power(int a, int p) {
  int r = 1, y = a;
  while (p) {
    if (p & 1) r = (1LL * r * y) % mod;
    p >>= 1;
    y = (1LL * y * y) % mod;
  }
  return r;
}
int ara[N];
pair<int, int> temp[N];
bool check(int n) {
  int mn = *min_element(ara, ara + n);
  for (int i = 0; i < n; i++) {
    if (temp[i].second != i) {
      if (temp[i].first % mn != 0) return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> ara[i];
      temp[i] = {ara[i], i};
    }
    sort(temp, temp + n);
    if (check(n))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
