#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       vector<long long> v;       for (long long i = 0; i < n; i++) {         cin >> a[i];         v.push_back(a[i]);       }       bool ans = true;       sort(v.begin(), v.end());       for (long long i = 0; i < n; i++) {         if (a[i] != v[i] && a[i] % v[0] > 0) {           ans = false;           break;         }       }       if (ans)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }   