#include <bits/stdc++.h>
using namespace std;
long long pw(long long x) {
  long long ans = x;
  for (int i = 0; i < 10; i++) {
    ans = ans * x;
  }
  return ans;
}
int lg(long long to) {
  int cnt = 0;
  while (to > 0) {
    cnt++;
    to = to / 2;
  }
  return cnt;
}
int factorize(int n) {
  int cnt = 0;
  for (int i = 2; i * i <= n; i++)
    while (n % i == 0) {
      cnt++;
      n /= i;
      if (n == 1) break;
    }
  if (n > 1) {
    cnt++;
  }
  return cnt;
}
int main() {
  int l;
  cin >> l;
  for (int u = 0; u < l; u++) {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b, b + n);
    int k = b[0];
    int d = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i] && a[i] % k != 0) {
        d = 0;
        break;
      }
    }
    if (d == 0) {
      cout << "NO";
    } else {
      cout << "YES";
    }
    cout << endl;
  }
  return 0;
}
