#include <bits/stdc++.h>
const long long MAX_SIZE = 2005;
using namespace std;
int main() {
  long long i, j, k, n, t;
  cin >> t;
  while (t--) {
    cin >> n;
    long long a[n], b[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b, b + n);
    for (i = 0; i < n; i++) {
      if (a[i] % b[0] == 0 || a[i] == b[i]) continue;
      break;
    }
    if (i == n)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
