#include <bits/stdc++.h>
using namespace std;
long long arr[100005];
long long brr[100005];
int main() {
  long long t, i, j, k, l, n, m;
  cin >> t;
  while (t--) {
    scanf("%lld", &n);
    m = LONG_MAX;
    for (i = 0; i < n; i++) {
      scanf("%lld", &arr[i]);
      brr[i] = arr[i];
      m = min(m, arr[i]);
    }
    sort(brr, brr + n);
    long long ans = 0;
    for (i = 0; i < n; i++) {
      if (arr[i] != brr[i] && arr[i] % m > 0) ans = 1;
    }
    if (ans) {
      printf("NO\n");
    } else {
      printf("YES\n");
    }
  }
}
