#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int min1 = INT_MAX;
    long long int n;
    cin >> n;
    long long int arr[n];
    long long int arr1[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      min1 = min(min1, arr[i]);
      arr1[i] = arr[i];
    }
    sort(arr, arr + n);
    bool poss = 1;
    for (int i = 0; i < n; i++) {
      if (arr[i] != arr1[i]) {
        if (arr1[i] % min1 != 0 or arr1[i] < min1) {
          poss = 0;
          break;
        }
      }
    }
    if (poss) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
