#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long a[N], mem[N][10][10];
bool vis[N], vis1[N];
vector<long long> v;
pair<long long, long long> p[N], p1[N];
set<int> s;
map<string, long long> mp;
queue<long long> q;
long long n, k, z;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    bool q = 0;
    for (int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]);
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
      if (a[i] != v[i] && v[i] % v[0]) {
        cout << "NO\n", q = 1;
        break;
      }
    }
    if (!q) cout << "YES\n";
    v.clear();
  }
}
