#include <bits/stdc++.h>   using namespace std;   clock_t time_p = clock();   void time_taken() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   const long long mod = 1e9 + 7;   const long long INF = 1e18;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int mn = *min_element((a).begin(), (a).end());     vector<int> inds, b;     for (int i = 0; i < n; i++) {       if (a[i] % mn == 0) inds.push_back(i), b.push_back(a[i]);     }     sort((b).begin(), (b).end());     int j = 0;     for (int x : inds) {       a[x] = b[j++];     }     if (is_sorted((a).begin(), (a).end())) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }     time_taken();     return 0;   }   