#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    long long b[n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    long long p = 0;
    sort(b, b + n);
    long long mn = b[0];
    long long flag = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] != b[i] && a[i] % mn > 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      cout << "NO";
    } else {
      cout << "YES";
    }
    cout << "\n";
  }
  return 0;
}
