#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n], b[n];
    long long m = INT_MAX;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
      m = min(m, a[i]);
    }
    sort(b, b + n);
    long long flag = 0;
    for (int i = 0; i < n; i++)
      if (a[i] != b[i] && a[i] % m > 0) flag = 1;
    if (flag)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
